c3p0连接池连接失败:java.sql.SQLException: Connections could not be acquired from the underlying database!

本文介绍了一个关于c3p0连接池配置的问题,作者最初无法正确连接数据库并收到错误提示。经过排查发现是配置文件中缺少必要的前缀,修改后问题得以解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

最近在使用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文件进行配置的,都要叫上前缀。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值