2つの列の値の間にあるすべての行を選択しようとしています。値はUNIXタイムスタンプですが、クエリは行をまったく返しません。なぜそうなるのでしょうか?
これが私のコードです:
public static ArrayList<Appointment> getAppointments(long start, long end) {
ArrayList<Appointment> appointments = new ArrayList<>();
try {
Statement stat = db.createStatement();
System.out.println("\n" + start + " -> " + end);
// debugging only
try (ResultSet rs = stat.executeQuery("SELECT * FROM appointments;")) {
while (rs.next()) {
long time = rs.getLong("date");
if (time >= start && time <= end) {
System.out.println("Should be adding to list");
}
}
} //
try (ResultSet rs = stat.executeQuery("SELECT * FROM appointments WHERE date BETWEEN " + start + " AND " + end + ";")) {
while (rs.next()) {
System.out.println("ADDING");
appointments.add(new Appointment(rs.getLong("date"), rs.getInt("duration")));
}
}
} catch (SQLException ex) {
}
System.out.println(appointments);
return appointments;
}
テーブルにこれらの値を持つ3つの行がある場合:
1347390000000 15
1347461100000 30
1347469200000 45
そして、出力は次のとおりです。
date = 1347390000000 duration = 15
date = 1347461100000 duration = 30
date = 1347469200000 duration = 45
1350141222283 -> 1350746022283
[]
1349536422283 -> 1350141222283
[]
1348931622283 -> 1349536422283
[]
1348330422283 -> 1348931622283
[]
1347725622283 -> 1348330422283
[]
1347120822283 -> 1347725622283
Should be adding to list
Should be adding to list
Should be adding to list
[]
1346516022283 -> 1347120822283
[]