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. Ever
Run below query to mysql DB to resolve the error
MariaDB [xxx> SET @@global.time_zone = '+00:00';
Query OK, 0 rows affected (0.062 sec)
MariaDB [xxx]> SET @@session.time_zone = '+00:00';
Query OK, 0 rows affected (0.000 sec)
MariaDB [xxx]> SELECT @@global.time_zone, @@session.time_zone;
The above program will generate that time zone error.
After your database name you have to add this: ?useTimezone=true&serverTimezone=UTC
. Once you have done your code will work fine.
Best of luck :)
After reading several posts on this topic, testing different configurations and based on some insights from this mysql bug thread that's what I have understood:
useLegacyDatetimeCode=true
, which in conjunction with useJDBCCompliantTimezoneShift=true
would make the application get the database time zone on every connection. In this mode GMT time zones such as 'British Summer Time' would be converted to the internal java/JDBC format. New time zones could be defined in a .properties file such as this oneuseJDBCCompliantTimezoneShift
) and legacy time format (useLegacyDatetimeCode
) were removed (see mysql jdbc connector changelog). therefore setting these 2 parameters has no effect as they are completely ignored (new default is useLegacyDateTimeCode=false
)serverTimezone
became mandatory if any of the time zones (application/database servers) are not in the format 'UTC+xx' or 'GMT+xx'jdbc:mysql://localhost:3306/myschema?serverTimezone=UTC
, even if your application / database servers are not in this timezone. The important is for the application connection string + database to be synchronized with the same time zone. In different words, simply setting serverTimezone=UTC with a different time zone on the database server will shift any dates extracted from the databasedefault-time-zone='+00:00'
(details in this StackOverflow post)I've solved this problem by configuring MySQL.
SET GLOBAL time_zone = '+3:00';
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.
spring.datasource.url = jdbc:mysql://localhost:3306/quartz_demo?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/resultout? useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root",""))
This is actually the solution to this problem, but don't just copy and paste it in your program. If you just read the line you will find 'resultout', that's the name of my database, and you have to write your's.
There are three string components, first one is url, second is username, and third one is password. In above paragraph we cleared, url. The second and third String components as said your username and password you have to change accordingly.
Thanks