【发布时间】:2011-02-20 22:32:16
【问题描述】:
我在 where 子句中使用带有时间戳的 PreparedStatement:
PreparedStatement s=c.prepareStatement("select value,utctimestamp from t where utctimestamp>=? and utctimestamp<?");
s.setTimestamp(1, new Timestamp(1273017600000L)); //2010-05-05 00:00 GMT
s.setTimestamp(2, new Timestamp(1273104000000L)); //2010-05-06 00:00 GMT
ResultSet rs = s.executeQuery();
if(rs.next()) System.out.println(rs.getInt("value"));
当我在客户端计算机上有不同的时区时,我得到的结果是不同的。这是 Oracle jdbc 中的错误吗?还是正确的行为?
Oracle 数据库版本为 10.2,我已尝试使用 oracle jdbc 瘦驱动程序版本 10.2 和 11.1。
参数是Timestamp,我预计途中不会进行时间转换。数据库列类型是 DATE,但我也用 TIMESTAMP 列类型进行了检查,结果相同。
有没有办法获得正确的结果?我无法将整个应用程序中的默认时区更改为 UTC。
感谢您的帮助
【问题讨论】:
-
请编辑您的问题并添加 t_begin 和 t_end 的类型。
标签: java oracle jdbc timestamp prepared-statement