一. 问题描述
使用JDBC
连接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.
二. 解决方案
方案一:
英文好的话直接看报错信息应该就能找到解决办法。需要在url
连接字符串后面加上?serverTimezone=UTC
,其中UTC
是统一标准世界时间。完整的连接字符串示例如下:
jdbc:mysql://localhost:3306/test?serverTimezone=UTC
方案二:
在mysql
中设置时区,默认为SYSTEM
,设置如下:
set global time_zone='+8:00'
公众号ID:longjiazuoA

未经允许不得转载:人生设计师 » JDBC连接MySql时出现时区无法识别的解决方案