数据库版本:8.0.x
搭建ssm项目时遇到的问题,使用的是Spring+Mybatis+c3po 学习搭建框架。
遇到:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
网上搜了终于找到了答案并成功解决,再次总结并希望能帮到遇到同样问题的朋友:
1.引用外部库 mysql-connector-java-8.0.26

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
2. 引入最新版的c3p0

<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
3.连接的驱动地址为"com.mysql.cj.jdbc.Driver" Mysql和mysql-connector都为8.0以上的版本时,连接驱动就不要再用:com.mysql.jdbc.Driver了,要引用com.mysql.cj.jdbc.Driver
4.建立连接时url的一些参数
url加上:useJDBCCompliantTimezoneShift=true&serverTimezone=UTC
jdbc.url=jdbc:mysql:
useUnicode=true&useJDBCCompliantTimezoneShift=true&serverTimezone=UTC&characterEncoding=utf8
到此,我的问题已经解决。
|