好的,所以我目前有一个具有以下时间的数据库:
id 1 开始时间 2013-09-09 15:05:10.0 结束时间 2013-09-09 15:05:10.0
id 2 开始时间 2013-09-09 15:09:54.0 结束时间 2013-09-09 15:09:54.0
id 3 开始时间 2013-09-09 15:20:46.0 结束时间 2013-09-09 15:20:46.0
id 4 开始时间 2013-09-09 15:21:06.0 结束时间 2013-09-09 15:21:06.0
id 5 开始时间 2013-09-09 15:21:34.0 结束时间 2013-09-09 15:21:34.0
id 6 开始时间 2013-09-09 15:22:34.0 结束时间 2013-09-09 15:22:34.0
id 7 开始时间 2013-09-09 15:23:06.0 结束时间 2013-09-09 15:25:34.0
现在,当我按位于此处的时间方法运行搜索时:
@Override
public ArrayList<AppointmentAccess> searchByTime(Timestamp startTime,
Timestamp endTime) throws SQLException {
ArrayList<AppointmentAccess> appointmentList = new ArrayList<AppointmentAccess>();
String preparedQuery = "Select DISTINCT * From Appointments where startTime <= appointments.endTime AND endTime >= appointments.startTime";
// Connect to database
try (Connection connection = DriverManager.getConnection(url, user,
password);
// Run SQL
PreparedStatement ps = connection.prepareStatement(preparedQuery);
// Get SQL results
ResultSet query = ps.executeQuery();) {
while (query.next()) {
AppointmentAccess appointment = new AppointmentAccess();
appointment.setStartTime(query.getTimestamp("starttime"));
appointment.setEndTime(query.getTimestamp("endtime"));
appointment.setAlarmReminder(query
.getBoolean("alarmreminder"));
appointment.setAllDay(query.getBoolean("allday"));
appointment.setDetails(query.getString("details"));
appointment.setLocation(query.getString("location"));
appointment.setTitle(query.getString("title"));
appointmentList.add(appointment);
}
}
// Returns a List of all the contacts
return appointmentList;
}
我的测试方法“searchTooLate、searchTooEarly 和 searchTimeBetweenAppointments”一直失败。我发送这些方法的时间是:
开始时间:“2013-09-09 16:05:09” 结束时间:“2013-09-09 16:22:35”
开始时间:“2013-09-09 15:24:06.0” 结束时间:“2013-09-09 15:25:30.0”
开始时间:“2013-08-09 14:05:09” 结束时间:“2013-08-09 16:22:35”
我究竟做错了什么!?