Dates With No Time or Timezone Component in Java/MySQL

Dates with no time or timezone component in Java/MySQL

I concluded that the best way in my current application (a simple utility using jdbc directly) was to insert directly as a string. For a bigger Hibernate app I might bother to write my own user type. Can't believe someone hasn't already solved this problem in some publicly available code though...

Store and retrieve a date in MySQL without any timezone information using MySQL Connector/J 8.0

In the past I've used this trick to make sure that the effective server time zone is the same as the client time zone:

String connectionUrl = "jdbc:mysql://localhost:3307/mydb?useUnicode=true"
+ "&serverTimezone=" + ZoneId.systemDefault().getId();
System.out.println(connectionUrl);
// jdbc:mysql://localhost:3307/mydb?useUnicode=true&serverTimezone=America/Denver

Connection conn = DriverManager.getConnection(connectionUrl, myUid, myPwd);

MySQL JDBC Driver 5.1.33 - Time Zone Issue

Apparently, to get version 5.1.33 of MySQL JDBC driver to work with UTC time zone, one has to specify the serverTimezone explicitly in the connection string.

jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC


Related Topics



Leave a reply



Submit