Home > Java > javaTutorial > Why Does MySQL JDBC Driver 5.1.33 Throw a SQLException Regarding Server Timezone?

Why Does MySQL JDBC Driver 5.1.33 Throw a SQLException Regarding Server Timezone?

Barbara Streisand
Release: 2024-12-13 12:13:10
Original
866 people have browsed it

Why Does MySQL JDBC Driver 5.1.33 Throw a SQLException Regarding Server Timezone?

MySQL JDBC Driver 5.1.33 and Unexpected JDBC Exception

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.
Copy after login

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template