解决[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)
[Druid-ConnectionPool-Create-332139408] ERROR com.alibaba.druid.pool.DruidDataSource - create connection SQLException是一个错误信息,表示在创建连接池时发生了SQLException。该错误通常与数据库连接相关。根据引用中的描述,您在运行SSM项目的登录功能时遇到了这个错误。这个错误可能是由于数据库连接配置有误或数据库连接池无法正常创建所致。 根据引用和引用的代码片段,可以看出在SSM项目中使用了Druid连接池来管理数据库连接。在配置数据源时,需要确保以下几点: 1. 确认数据库连接参数(如url、username、password、driverClassName)是否正确配置。 2. 确认项目中是否正确引入了Druid相关的依赖。 3. 确认数据源的最大活跃连接数和最小空闲连接数等参数是否符合需求。 您可以根据以上提示检查您的配置是否正确,并确保项目中引入了所需的依赖。如果问题仍然存在,可能需要进一步排查数据库连接配置、数据库服务器状态以及网络连接等方面的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [DruidJDBCUtils.java](https://download.csdn.net/download/Zhang52_Cheng/12142588)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【已解决】ERROR [Druid-ConnectionPool-Create-322375688] - create connection SQLException异常](https://blog.csdn.net/qq_51452131/article/details/128051665)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ERROR com.alibaba.druid.pool.DruidDataSource - create connection SQLException, url](https://blog.csdn.net/qq_44866828/article/details/115921900)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值