java.sql.SQLException: The server time zone value ‘�й���ʱ��‘ is unrecognized or represents more tha
Posted 闲言_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.sql.SQLException: The server time zone value ‘�й���ʱ��‘ is unrecognized or represents more tha相关的知识,希望对你有一定的参考价值。
异常产生环境
SpringBoot项目,配置mysql数据库时产生
异常描述
java.sql.SQLException: 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.
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) ~[na:1.8.0_101]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_101]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_101]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_101]
异常原因
在SpringBoot项目下,没有指定MySQL驱动版本的情况下它自动依赖的驱动是8.0.12很高的版本,这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题
解决办法
spring:
datasource:
url: jdbc:mysql://localhost:3306/*****?serverTimezone=UTC
username: *****
password: *****
driver-class-name: com.mysql.jdbc.Driver
以上是关于java.sql.SQLException: The server time zone value ‘�й���ʱ��‘ is unrecognized or represents more tha的主要内容,如果未能解决你的问题,请参考以下文章
Oracle DB:java.sql.SQLException:关闭连接
Cause: java.sql.SQLException: 请求的转换无效 ; uncategorized SQLException for SQL []; SQL state [99999]; er
java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 发生错误
Java:Sqlexception:位置不支持的 SQL92 令牌:178