PreparedStatement and setTimestamp in oracle jdbc

前端 未结 1 1822
眼角桃花
眼角桃花 2020-12-03 03:18

I am using PreparedStatement with Timestamp in where clause:

PreparedStatement s=c.prepareStatement(\"select value,utctimestamp from t where utctimestamp>         


        
相关标签:
1条回答
  • 2020-12-03 04:00

    To set a timestamp value in a PreparedStatement in UTC timezone one should use

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

    The Timestamp value is always UTC, but not always the jdbc driver can automatically sent it correctly to the server. The third, Calendar, parameter helps the driver to correctly prepare the value for the server.

    0 讨论(0)
提交回复
热议问题