3

With reference to an older post: Set default timezone H2 database

Is it possible in the current build of H2 to set a timezone at the Connection/DB level rather than relying on the timezone of the JVM that loaded the driver? I want to explicitly set the Connection to our H2 DB to be UTC, and not rely on a system property. I fully understand that the DB itself doesn't store timezone info but it's the JDBC driver that's doing some interpretation of timezones when accessing the data.

If its not available, would it be possible to add such a feature (perhaps in the JDBC URL string)?

Community
  • 1
  • 1
user2591854
  • 182
  • 3
  • 15
  • It sounds like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Could you explain what problem you want to solve? – Thomas Mueller Dec 09 '14 at 07:03
  • I want to ensure that datetimes are stored and retrieved in UTC. Right now, I have an H2 DB that has timezone agnostic timestamps stored. The retrieved value of these timestamps are dependent on the timezone of the invoking JVM. I do want to allow this if at all possible - Id like my application to be able to specify, on the connection string, what the timezone of all retrieved timestamps will be. – user2591854 Dec 10 '14 at 16:00
  • Sorry I don't understand what you mean. Could you give an concrete example of the problem you want to solve. – Thomas Mueller Dec 10 '14 at 20:46
  • @ThomasMueller, I will open you a bug around usage of time zone. I found in in 1.3.175. Any chances some stuff has changed in version 1.4.xxx ? – Tony Chemit Jun 13 '17 at 18:06
  • 1
    @TonyChemit Yes there were many changes since then. – Thomas Mueller Jun 14 '17 at 19:02
  • @ThomasMueller, yes I just tried the 1.4.xxx version, and it works like a charm, thanks a lot! – Tony Chemit Jun 28 '17 at 09:58

1 Answers1

2

I had the same issue and implemented a quick workaround, by putting these before loading the H2 DB driver.

System.setProperty("user.timezone", "UTC");
TimeZone.setDefault(null);

Class.forName("org.h2.Driver");
Michael
  • 41
  • 4