oracle jdbc中的PreparedStatement和setTimestamp

我在where子句中使用PreparedStatement和Timestamp:

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。

谢谢你的帮助

要在UTC时区的PreparedStatement中设置时间戳值,应该使用

 stmt.setTimestamp(1, t, Calendar.getInstance(TimeZone.getTimeZone("UTC"))) 

Timestamp值始终为UTC,但并非总是jdbc驱动程序可以自动将其正确发送到服务器。 第三个Calendar参数可帮助驱动程序正确准备服务器的值。