项目场景:
项目场景:在Tomca学习中出现[Druid-ConnectionPool-Create-1563341029]和Caused by: com.mysql.cj.exceptions这样的错误,导致无法连接数据库

问题描述:
出现错误:12-Mar-2021 21:10:44.200 严重 [Druid-ConnectionPool-Create-1563341029] com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl.error create connection SQLException, url: jdbc:mysql:///day14, errorCode 0, state 01S00
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 specific 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 specific time zone value if you want to utilize time zone support.
原因分析:
原因:com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver有区别
com.mysql.jdbc.Driver 是 mysql-connector-java 5中的,
com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的
JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone,否则就会报错
在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:
url: jdbc:mysql://localhost/db?serverTimezone=Asia/Shanghai
解决方案:
在配置文件druid.properties中的URL里添加serverTimezone=UTC即可解决:

版权声明:本文参考优快云博主「大誌」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接: [https://blog.youkuaiyun.com/weixin_42236404/article/details/89070533](https://blog.youkuaiyun.com/weixin_42236404/article/details/89070533)
本文介绍了在使用Druid连接池连接MySQL时遇到的时区配置错误问题,详细解释了错误原因并提供了解决方案,包括如何正确设置serverTimezone参数。
5095

被折叠的 条评论
为什么被折叠?



