Some background:
I have a Java 1.6 webapp running on Tomcat 7. The database is MySQL 5.5. Previously, I was using Mysql JDBC driver 5.1.23 to connect to the DB. Everything worked. I recently upgraded to Mysql JDBC driver 5.1.33. After the upgrade, Tomcat would throw this error when starting the app.
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.
Why is this happening?
The connection string should be set like this:
If you are defining the connection in an
xml
file (such aspersistence.xml
,standalone-full.xml
, etc..), instead of&
you should use&
or use aCDATA
block.I added in mysql config file in section [mysqld]
And restart mysql server:
Where +03:00 my UTC time zone.
Path to config file on my os ubuntu 16.04:
WARNING: IF YOUR TIME ZONE HAVE SUMMER AND WINTER TIME. YOU MUST CHANGE UTC IN CONFIG IF CHANGE TIME. TWICE IN YEAR(USUALLY) OR SET CRONTAB WITH SUDO.
My url jdbc connection:
I have the same problem and i solved it append only "?serverTimezone=UTC" to my string connection.
#sinossi my problem:
java.sql.SQLException: The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
If you are using Maven, you can just set another MySQL connector version (I had the same error, so i changed from 6.0.2 to 5.1.39) in
pom.xml
:As reported in another answers, this issue has been fixed in versions 6.0.3 or above, so you can use the updated version:
Maven will automatically re-build your project after you save the
pom.xml
file.Agree with @bluecollarcoder answer, but it's better to use
TimeZone.getDefault().getID();
at the end of the connection string:In this case
Timezone
parameter automatically updates depending on the local machine timezone.