项目场景:

项目场景:在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即可解决:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210312212217500.png在这里插入图片描述


版权声明:本文参考CSDN博主「大誌」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接: [https://blog.csdn.net/weixin_42236404/article/details/89070533](https://blog.csdn.net/weixin_42236404/article/details/89070533)
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐