java.sql.SQLException: Io 異常: Connection refused

xz43發表於2012-09-19
客戶提供了配置好的RAC資料庫服務,要求我們切換到該環境下使用。如是,我就修改了jdbc連線的URL配置資訊,改為如下:
 
url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.12)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.13)(PORT = 1521))(LOAD_BALANCE = yes)(FAILOVER = ON)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ZZD)(FAILOVER_MODE=(TYPE = SELECT)(METHOD = BASIC)(RETIRES = 20)(DELAY = 15))))
 
其他保持不變,啟動應用伺服器,結果日誌狂拋錯:
java.sql.SQLException: Io 異常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169870336)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:335)
        at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:361)
        at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:68)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:87)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)
        at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)
        at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)
java.sql.SQLException: Io 異常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169870336)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:335)
        at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:361)
        at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:68)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:87)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)
        at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)
        at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)
如是,修改URL,改為連線RAC裡面的單機加例項名,2臺都可以連線成功。改為單機加服務名ZZD,一樣的報錯。客戶端配置ZZD,透過sqlplus連線正常,排除RAC配置問題。
想盡各種辦法,也沒找到原因,進入應用程式的lib目錄,找到oracle的jdbc驅動jar,居然有classes12.jar和ojdbc14.jar兩個版本的驅動,如是刪除classes12.jar,再次啟動應用伺服器,報下面的錯誤
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
192.168.1.13:1521:ZZD
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
        at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:439)
        at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:68)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:87)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)
        at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)
        at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)
然後,我把URL切換為最上面的叢集配置方式,再次啟動應用,一切正常了。
 
看來影響jdbc連線的根源,還是jdbc驅動的版本了,不同的版本,對叢集的支援不一樣,害得我折騰了好久。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9399028/viewspace-744251/,如需轉載,請註明出處,否則將追究法律責任。

相關文章