Bug #82881 Can't generate a connect when my connect string without a serverTimezone param
Submitted: 7 Sep 2016 1:55 Modified: 8 Sep 2016 11:29
Reporter: shine king Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:6.0.3 OS:Any
Assigned to: CPU Architecture:Any
Tags: timezone

[7 Sep 2016 1:55] shine king
Description:
My connect string is 'jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8'
When I use Connector/J 5.1.x version´╝îthis connect string have no problem in my server tomcat.
But when I use Connector/J 6.0.3, it will throw a Exception when create connection.
The exception stack is :

Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'CST' 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.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_73]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_73]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_73]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_73]
	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54) ~[mysql-connector-java-6.0.3.jar:6.0.3]
	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) ~[mysql-connector-java-6.0.3.jar:6.0.3]
	at com.mysql.cj.jdbc.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:118) ~[mysql-connector-java-6.0.3.jar:6.0.3]
	at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:315) ~[mysql-connector-java-6.0.3.jar:6.0.3]
	at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2446) ~[mysql-connector-java-6.0.3.jar:6.0.3]
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1797) ~[mysql-connector-java-6.0.3.jar:6.0.3]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1653) ~[mysql-connector-java-6.0.3.jar:6.0.3]

How to repeat:
MySQL server system_time_zone variable is CST
The connect string without a serverTimezone parameter.

Suggested fix:
I find that caused by timezone setting
At version 5.1.x, the ConnectionImpl.configureTimezone() will config the timezone setting from MySQL server, but before get timezone config from server environment, it have a "getUseTimezone() || !getUseLegacyDatetimeCode()" determine statement, as default it will be false, so the timezone config from java environment.
But at version 6.0.3, it has't this determine before get timezone from server, and because of TimeUtil parse a timezone string from file TimeZoneMapping.properties, when can't get a value of key 'CST', it will throw a Exception.

I think if can get java default timezone setting when catch a exception which throw with get timezone from MySQL server?

Thank you
[8 Sep 2016 11:29] Chiranjeevi Battula
Hello  shine king,

Thank you for the bug report.
This is most likely duplicate of Bug #82192, please see Bug #82192.

Thanks,
Chiranjeevi.