我想删除数据库中保存的时间列表,其中日期(end_time - timestamp)大于特定员工的参考日期(employeeId - 整数)。 该查询在pgAdmin III上完美工作。但是我无法使它在JDBC中工作。 它可以工作,但会删除特定员工的所有内容,而不仅仅是我想要的日期。我看起来像忽略了Where子句中的日期。另外,我没有任何例外。 变量nextDayTimestamp出来就像:'2017-03-31 12:00:00.0' 任何人都可以请帮忙吗?删除在PgAdmin 3中工作但在Java JDBC上不工作的查询
public void deleteBigListOfPeriodOfWorkFutureOnly(int employeeId, LocalDate referenceDate) {
Connection myConn = null;
PreparedStatement myStmt = null;
try {
myConn = dataSource.getConnection();
LocalDate nextDay = referenceDate.plusDays(1);
Timestamp nextDayTimestamp = Timestamp.valueOf(LocalDateTime.of(nextDay, LocalTime.NOON));
String sql = "delete from working_time where working_time.end_time > ? and employee_id = ?";
myStmt = myConn.prepareStatement(sql);
myStmt.setTimestamp(1, nextDayTimestamp);
myStmt.setInt(2, employeeId);
myStmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
CloseConnection.close(myConn, myStmt, null);
}
}
}
什么是数据库中的'end_time',时间戳或日期时间? –
我想第一个条件总是如此,就像@ GuillaumeF.said一样,它可能与类型有关。 –
@GuillaumeF。 end_time是没有时区的时间戳。 – evzpav