c3p0 池无法建立连接。如何调试这个?
我在服务器上安装了 Tomcat 和 PostgreSQL。我在尝试使用 c3p0 池从 servlet 连接到 PostgreSQL 数据库时遇到连接问题。
如果我在笔记本电脑上本地运行 Tomcat,我就可以访问数据库。我还可以使用 psql (即命令行 sql 实用程序)从服务器连接到数据库。但是,当我尝试将 servlet 部署到服务器并建立连接时,出现以下错误:
java.sql.SQLException: Connections could not be acquired from the underlying database!
com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
我应该检查什么来定位问题?这应该是一个小问题,但可能是由于凌晨 4 点我错过了一些东西:) 提前致谢!
PS:允许所有网络接口连接到数据库。 PostgreSQL JDBC 驱动程序和 c3p0 池以 WAR 形式分发。 Tomcat 配置是非常默认的。不使用 JNDI。
I have a Tomcat and PostgreSQL installed on a server. I'm having a connection problem trying to connect from my servlet to PostgreSQL database using c3p0 pool.
I can reach DB if I'm running Tomcat locally on my laptop. Also I can connect from server to DB using psql (i.e. command line sql utility). But when I'm trying to deploy my servlet to server and establish a connection I'm getting the following error:
java.sql.SQLException: Connections could not be acquired from the underlying database!
com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
What should I check to locate a problem? It should be a trivial issue but may be due to 4 a.m. I'm missing something :) Thanks in advance!
PS: Connection from all network interfaces are allowed to database. PostgreSQL JDBC driver and c3p0 pool are distributed in WAR. Tomcat configuration is very default. JNDI is not used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要检查一些事情:
(例如
/etc/tomcat5.5/policy.d/02debian.policy)
/etc/postgresql/pg_hba.conf)
就我而言,c3p0 向我隐藏了重要信息
You need to check a few things:
(e.g.
/etc/tomcat5.5/policy.d/02debian.policy)
/etc/postgresql/pg_hba.conf)
in my case c3p0 was hiding important information from me
添加到 @Alexey 的答案,我在 Tomcat 和 PostgreSQL 9.4 中遇到了这个问题。就我而言,是
postgres
中的md5
身份验证方法导致了该问题。如果您使用的是
Windows 服务器
或RHEL 服务器
,请确保更新pg_hba.conf
文件中的身份验证方法。修改为trust
并重启postgresql。Adding to @Alexey's answer, I had this issue with Tomcat and PostgreSQL 9.4. In my case, the
md5
authentication method inpostgres
was causing the issue.If you are using
Windows server
orRHEL server
, make sure you update the authentication method inpg_hba.conf
file. Modify it totrust
and restart postgresql.