解决[Druid-ConnectionPool-Create-xxx]和InvalidConnectionAttributeException

项目场景:

项目场景:在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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值