Home >Java >javaTutorial >Why Does MySQL JDBC Driver 5.1.33 Throw a SQLException Regarding Server Timezone?
A Java web application utilizing JDBC driver 5.1.23 experienced no issues when connecting to a MySQL 5.5 database. However, upon upgrading to driver version 5.1.33, Tomcat began encountering an exception upon application startup. The error message prompted an investigation into why such an error occurred.
The error encountered was:
WARNING: Unexpected exception resolving reference java.sql.SQLException: The server timezone value 'UTC' is unrecognized or represents more than one timezone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc timezone value if you want to utilize timezone support.
To rectify this issue, it was determined that MySQL JDBC driver 5.1.33 requires explicit specification of the serverTimezone parameter in the connection string for UTC time zone support. This is achieved by adding the following to the connection string:
?serverTimezone=UTC
This addition ensures that the driver uses the specified timezone for temporal operations, resolving the exception and enabling the application to function correctly. Therefore, the modified connection string appears as follows:
jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
The above is the detailed content of Why Does MySQL JDBC Driver 5.1.33 Throw a SQLException Regarding Server Timezone?. For more information, please follow other related articles on the PHP Chinese website!