无法使用 c3p0 连接到位于 127.0.0.1 的 MySQL 服务器
Can't connect to MySQL server at 127.0.0.1 using c3p0
尝试使用 Java 中的以下代码与 c3p0 连接到 MySQL 服务器:
comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/" + Dbname);
comboPooledDataSource.setUser(Username);
comboPooledDataSource.setPassword(Password);
comboPooledDataSource.setInitialPoolSize(15);
comboPooledDataSource.setMaxPoolSize(20);
comboPooledDataSource.setMinPoolSize(10);
connection = comboPooledDataSource.getConnection();
尽管我已经检查过数据库已启动并且 运行 并且我可以使用 Python 连接到它,但它一直向我抛出以下错误:
INFO: Initializing c3p0 pool...com.mchange.v2.c3p0.ComboPooledDataSource@b4c966a[ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> null, driverClass -> null, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> b4c966a, idleConnectionTestPeriod -> -1, initialPoolSize -> 30, jdbcUrl -> jdbc:jtds:mysql://127.0.0.1:3306/sip_base, loginTimeout -> 0, maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ]
Μαϊ 12, 2015 10:41:12 ΠΜ com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7e2889c7 -- 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).
Μαϊ 12, 2015 10:41:12 ΠΜ com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@372567de -- 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).
Exception in thread "main" java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:264)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)
at gov.nist.sip.proxy.extended.DBServer.<init>(DBServer.java:52)
at gov.nist.sip.proxy.extended.DBServer.getInstance(DBServer.java:64)
at gov.nist.sip.proxy.extended.DBServer.main(DBServer.java:161)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:972)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
... 5 more
您似乎试图将初始池大小设置为大于最大池大小 - 这不太可能奏效。
comboPooledDataSource.setInitialPoolSize(30); // <<-- Reduce this
comboPooledDataSource.setMaxPoolSize(20); // <<-- to something less than this.
我已经修好了。原来我没有安装jdbc服务器。
尝试使用 Java 中的以下代码与 c3p0 连接到 MySQL 服务器:
comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/" + Dbname);
comboPooledDataSource.setUser(Username);
comboPooledDataSource.setPassword(Password);
comboPooledDataSource.setInitialPoolSize(15);
comboPooledDataSource.setMaxPoolSize(20);
comboPooledDataSource.setMinPoolSize(10);
connection = comboPooledDataSource.getConnection();
尽管我已经检查过数据库已启动并且 运行 并且我可以使用 Python 连接到它,但它一直向我抛出以下错误:
INFO: Initializing c3p0 pool...com.mchange.v2.c3p0.ComboPooledDataSource@b4c966a[ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> null, driverClass -> null, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> b4c966a, idleConnectionTestPeriod -> -1, initialPoolSize -> 30, jdbcUrl -> jdbc:jtds:mysql://127.0.0.1:3306/sip_base, loginTimeout -> 0, maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ]
Μαϊ 12, 2015 10:41:12 ΠΜ com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7e2889c7 -- 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).
Μαϊ 12, 2015 10:41:12 ΠΜ com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@372567de -- 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).
Exception in thread "main" java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:264)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)
at gov.nist.sip.proxy.extended.DBServer.<init>(DBServer.java:52)
at gov.nist.sip.proxy.extended.DBServer.getInstance(DBServer.java:64)
at gov.nist.sip.proxy.extended.DBServer.main(DBServer.java:161)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:972)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
... 5 more
您似乎试图将初始池大小设置为大于最大池大小 - 这不太可能奏效。
comboPooledDataSource.setInitialPoolSize(30); // <<-- Reduce this
comboPooledDataSource.setMaxPoolSize(20); // <<-- to something less than this.
我已经修好了。原来我没有安装jdbc服务器。