在java中使用JDBC连接mysql数据库时,报以下的错:Exception in thread “main” java.sql.SQLException:

75 阅读1分钟

项目场景:

在java中使用JDBC连接mysql数据库时,报以下的错:Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone.


问题描述

在java中使用JDBC连接mysql数据库时,运行后会报出The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. 的错误。此时的URL设定如下:

String url = "jdbc:mysql://localhost:3306/bookbd";

原因分析:

这是因为在当前版本的mysql,默认的时区与本地的时区不一致,服务器无法识别多个时区


解决方案:

只需要在url后面加上
?serverTimezone=GMT%2B8
即可解决