项目场景:
ssm项目连接mysql 8.0 报错:Connections could not be acquired from the underlying database!
问题描述:
### 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!
### The error may exist in file [F:\i_code\bobssm\target\classes\mapper\BookMapper.xml]
### The error may involve com.bob.dao.BookDao.queryById
### The error occurred while executing a query
### 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!
原因分析:
发现项目里引用的mysql-connector-java 版本还是5.1.37,但是所用的mysql是8.0版本的
解决方案:
使用8.0版本的 mysql-connector
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
<scope>runtime</scope>
</dependency>