做ssm整合遇到这个错误
错误截图
Caused by: 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!
### The error may exist in com/guo/dao/BookMapper.xml
### The error may involve com.guo.dao.BookMapper.queryAllBook
### 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!
我使用c3p0配置数据库连接池
配置文件
database.properties
经过一系列排查,看了不下十几个个博客原来是username出现问题
我们用dbcp去配置数据库连接池时,${username}并非db.properties文件中的username。而是映射到了系统环境变量中的username,这里直接变成了主机名,而不是root
所以我们在配置db.properties时,通常都是以jdbc或db作为前缀,这样就可以避免重名的问题.
改成:
配置文件
database.properties
在修改之后,测试一下,没有问题
原文链接:https://blog.csdn.net/SuperBetterMan/article/details/118581421