今天在使用mybatis時候,出現了一個時區報錯,挺奇怪的。
報錯如下:
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���ʱ��' 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)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2121)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2145)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
... 87 common frames omitted
看字面意思是說我本地有不止一個時區,必須配置一個確定的時區才能使用時間支持。具體是什麼原因導致的我也不知道,有可能是我本地開小飛機導致的吧,查詢資料得知,只需要在jdbc連接串後拼接時區代碼即可,至於是不是東八區時間,這個沒影響,代碼如下:
serverTimezone=UTC
我的初始連接串爲:
jdbc:mysql://localhost:3306/e3mall?useUnicode=true&characterEncoding=UTF-8&useSSL=false
添加時區後完整的串爲:
jdbc:mysql://localhost:3306/e3mall?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
這樣就可以解決該報錯了。