1. 程式人生 > 資料庫 >java.sql.SQLRecoverableException: IO 錯誤: Invalid connection string format, a valid format is: “host:

java.sql.SQLRecoverableException: IO 錯誤: Invalid connection string format, a valid format is: “host:

java.sql.SQLRecoverableException: IO 錯誤: Invalid connection string format, a valid format is: "host:port:sid" 
 

java.sql.SQLRecoverableException: IO 錯誤: Invalid connection string format, a valid format is: "host:port:sid" 
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
	at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
	at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: oracle.net.ns.NetException: Invalid connection string format, a valid format is: "host:port:sid" 
	at oracle.net.resolver.AddrResolution.resolveSimple(AddrResolution.java:510)
	at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:441)
	at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
	at oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
	at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
	... 13 more
一月 11, 2021 10:19:43 下午 com.mchange.v2.resourcepool.BasicResourcePool 
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@78e117e3 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
一月 11, 2021 10:19:43 下午 com.mchange.v2.resourcepool.BasicResourcePool 
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@78e117e3 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937)
	at com.dao.CostDaoImpl.save(CostDaoImpl.java:34)
	at com.test.TestDao.test01(TestDao.java:38)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
	at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	... 27 more
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.awaitAvailable(BasicResourcePool.java:1507)
	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
	... 30 more
Caused by: java.sql.SQLRecoverableException: IO 錯誤: Invalid connection string format, a valid format is: "host:port:sid" 
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
	at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
	at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: oracle.net.ns.NetException: Invalid connection string format, a valid format is: "host:port:sid" 
	at oracle.net.resolver.AddrResolution.resolveSimple(AddrResolution.java:510)
	at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:441)
	at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
	at oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
	at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
	... 13 more

 未修改的原始碼

 

使用的是idea2019,junit4測試,Spring手動注入。Oracle11g,Oracle7.jar,c3p0-0.9.5.5.jar,c3p0-oracle-thin-extras-0.9.5.jar,mchange-commons-java-0.2.20.jar  。

恩,很難受,查詢了許久,結果發現是查詢問題的方向錯了。一直查詢的是這個問題,哎。org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

問題原因,由於Oracle連線的url出的問題,埠號1521後面應該是 :號加上資料庫名稱,結果寫成了  .  哎,難受,白白花費了幾個小時的時間