问题描述:
最近在使用c3p0连接池写一个小项目,在测试时始终无法正确连接数据库,报错如下:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@669bed27 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.lang.NullPointerException
...
java.sql.SQLException: Connections could not be acquired from the underlying database!
...
Process finished with exit code -1
在网上查了很多资料大多都说是检查配置对不对,我的配置是使用c3p0.properties:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
user=root
password=root
很多博客上的教程也是这么写的,但是始终通不过测试。
解决方法
最终在一篇博客上找到了答案。真确的配置是:
c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.jdbcUrl=jdbc:mysql://localhost:3306/test
c3p0.user=root
c3p0.password=root
改成这样后终于成功通过了测试。
总结
这个问题卡了一上午。最后才发现原来仅仅是前缀没加。
以后记住,采用properties文件进行配置的,都要叫上前缀。