带有Amazon Postgres RDS的c3p0

时间:2019-05-06 11:56:02

标签: java postgresql amazon-rds c3p0

我正在尝试使用c3p0连接到RDS,当不使用RDS时,代码可以运行,但对于RDS则失败, 带有DriverManager的纯Java可以创建连接,使我相信问题出在c3p0

connectionPool.setUser(user);
connectionPool.setPassword(password);
connectionPool.setJdbcUrl(jdbc);
try {
    Connection con = connectionPool.getConnection();//fails after several seconds
    con.isValid(1);
    con.close();
} catch (SQLException e) {
    e.printStackTrace();
}
try {
    Connection con = DriverManager.getConnection(jdbc, user, password);
    con.isValid(1);//true
    con.close();
} catch (SQLException e) {
    e.printStackTrace();
}

但是c3p0归咎于postgres

  

java.sql.SQLException:无法从基础数据库获取连接!       在com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)       在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)       在com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)       在我的代码中,“ connectionPool.getConnection()”行   由以下原因引起:com.mchange.v2.resourcepool.CannotAcquireResourceException:ResourcePool无法从其主工厂或源中获取资源。       在com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)       在com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)       在com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)       在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)       在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)       ...另外13个   引起原因:org.postgresql.util.PSQLException:此ResultSet已关闭。       在org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2852)       在org.postgresql.jdbc2.AbstractJdbc2ResultSet.setFetchSize(AbstractJdbc2ResultSet.java:1875)       在org.postgresql.jdbc4.Jdbc4Statement.createResultSet(Jdbc4Statement.java:37)       在org.postgresql.jdbc2.AbstractJdbc2Statement $ StatementResultHandler.handleResultRows(AbstractJdbc2Statement.java:221)       在org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1853)       在org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)       在org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)       在org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:405)       在org.postgresql.jdbc2.AbstractJdbc2Connection.execSQLUpdate(AbstractJdbc2Connection.java:382)       在org.postgresql.jdbc2.AbstractJdbc2Connection.getTransactionIsolation(AbstractJdbc2Connection.java:904)       在com.mchange.v2.c3p0.impl.NewPooledConnection。(NewPooledConnection.java:120)       在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:240)       在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)       在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)       在com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)       在com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)中       在com.mchange.v2.resourcepool.BasicResourcePool.access $ 700(BasicResourcePool.java:44)       在com.mchange.v2.resourcepool.BasicResourcePool $ ScatteredAcquireTask.run(BasicResourcePool.java:1870)       在com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:696)   引用

我尝试使用connectionPool.setDriverClass,但没有帮助 我使用的是hibernate-c3p0 https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0/5.4.2.Final上的java11和c3p0,试图更新到最新的beta,这没有帮助

0 个答案:

没有答案