Tag Archives: com.mysql.cj.jdbc.util.TimeUtil.loadTimeZoneMappings(TimeUtil.java:163)

[Solved] MySQL Error: com.mysql.cj.jdbc.util.TimeUtil.loadTimeZoneMappings(TimeUtil.java:163)

Question:

Mysql database version 5.6, jdbc driver package mysql-connector-java-5.1.49-bin version, start tomcat, and an error is reported when connecting to the database. Details:

java.lang.NullPointerException
    java.util.Properties$LineReader.readLine(Properties.java:434)
    java.util.Properties.load0(Properties.java:353)
    java.util.Properties.load(Properties.java:341)
    com.mysql.cj.jdbc.util.TimeUtil.loadTimeZoneMappings(TimeUtil.java:163)
    com.mysql.cj.jdbc.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:109)
    com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:308)
    com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2474)
    com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1817)
    com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1673)
    com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:656)
    com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:349)
    com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)

After query, it is said that the exception is thrown because the format of the MySQL server time zone (inherited from the system time zone) is different from that expected by the MySQL connector.

Solution:

Add the JDBC URL to the servertimezone, for example:

jdbc.url=jdbc:mysql://localhost:3306/xuejia?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8

servertimezone = UTC , where UTC is the unified standard world time; China is in the East eighth district. If you need to specify the time zone as China, you can modify the configuration to servertimezone = GMT% 2B8 .

About time zone:

UTC, coordinated universal time. UTC is a time measurement system based on atomic time and second length, which is as close as possible to GMT in time. To ensure that UTC does not differ from GMT by more than 0.9 seconds, positive or negative leap seconds will be added to UTC if necessary. UTC is now used as world standard time
GMT: Greenwich mean time, that is, universal time. Noon in GMT refers to the time when the sun crosses the Greenwich meridian (primary meridian). However, due to the uneven and irregular rotation of the earth, GMT is not accurate, and it is no longer used as the world standard time
UTC is basically the same as GMT, with an error of no more than 0.9 seconds