【发布时间】:2021-12-04 13:39:02
【问题描述】:
我正在查询:
SELECT *
FROM test_test
where user_id_one = 123456789
and user_id_two = 123456788
and action_taken = 'CHECK'
and games_type = 'LUDDO'
and modified_on >= '2021-10-07 05:53:48'::timestamp
and modified_on < '2021-10-07 05:53:49'::timestamp
我在 pgAdmin 控制台中得到了结果,但是当我使用 Java 代码尝试相同的事情时,它不起作用:
ps = conn.prepareStatement("SELECT * FROM test_test where user_id_one = ? and user_id_two = ? and action_taken = ? and games_type = ? and modified_on >= ?::timestamp and modified_on < ?::timestamp");
ps.setInt(1,testTest.getUserIdOne());
ps.setInt(2,testTest.getUserIdTwo());
ps.setString(3,testTest.getActionTaken());
ps.setString(4,testTest.getGamesType());
ps.setString(5,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(collusionDashboard.getModifiedOn().toDate()));
ps.setString(6,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(collusionDashboard.getModifiedOn().plusSeconds(1).toDate()));
resultSet = ps.executeQuery();
log.info("{}",ps);
if (resultSet.next()) == getting false here {
}
当我记录数据时,我得到了与上面提到的相同的查询。
【问题讨论】:
-
您不应将时间戳值作为字符串传递。使用
setObject()传递LocalDateTime的实例
标签: java postgresql jdbc