4

According to the JDBC 4.0 Specification, does JDBC set the database session time zone to that of the Java virtual machine (i.e. TimeZone#getDefault())?

Derek Mahar
  • 27,608
  • 43
  • 124
  • 174

1 Answers1

2

No, JDBC by default doesn't do it, but it is possible that your database driver does that. Take a look at the docs of your specific driver.

ZeissS
  • 11,867
  • 4
  • 35
  • 50
  • So the JDBC standard does not specify how the database driver should set the session time zone? – Derek Mahar Nov 08 '10 at 12:00
  • So if you change JDBC drivers, and the new driver sets the session time zone differently than the initial driver, and the driver translates dates to the session time zone, your application will store the same Java date with a different database column value? – Derek Mahar Nov 08 '10 at 12:10
  • 1
    Maybe, maybe not. Thats why it is best to explizitly specify such things ;) – ZeissS Nov 08 '10 at 12:29
  • 2
    ZeissS, according to http://stackoverflow.com/questions/4123534/before-writing-a-java-date-to-an-sql-timestamp-column-does-jdbc-translate-the-da/4124620#4124620, the MySQL JDBC driver doesn't set the database session time zone, but it does translate a given date from the local to the server time zone. The PostgreSQL JDBC driver, on the other hand, translates a given date to the default calendar time zone. So you're correct that time zone translation is specific to the JDBC driver. – Derek Mahar Nov 09 '10 at 17:45