Java can't connect to Oracle Database
September 20, 2010
I had a problem talking to my Oracle database from Java. Python worked fine. SQL*Plus worked fine. telnet to the Oracle port worked fine. Any connections from Java would give an error with the root cause of:
Io exception: The Network Adapter could not establish the connection.
This had me stumped for a while. We tried copying in a co-workers configuration and Oracle driver (ojdbc6.jar) with no benefit, although the newer driver did give a slightly different error:
java.sql.SQLException: The Network Adapter could not establish the connection oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412) oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531) oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221) oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503) oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207) oracle.net.ns.NetException: The Network Adapter could not establish the connection oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359) oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422) oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672) oracle.net.ns.NSProtocol.connect(NSProtocol.java:237) oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042) oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301) oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531) oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221) oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503) oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207) oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:139) oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:88) oracle.jdbc.pool.OracleImplicitConnectionCache.makeCacheConnection(OracleImplicitConnectionCache.java:1583) oracle.jdbc.pool.OracleImplicitConnectionCache.makeOneConnection(OracleImplicitConnectionCache.java:515) oracle.jdbc.pool.OracleImplicitConnectionCache.defaultUserPrePopulateCache(OracleImplicitConnectionCache.java:222) oracle.jdbc.pool.OracleImplicitConnectionCache.<init>(OracleImplicitConnectionCache.java:198) oracle.jdbc.pool.OracleConnectionCacheManager.createCache(OracleConnectionCacheManager.java:298) oracle.jdbc.pool.OracleDataSource.cacheInitialize(OracleDataSource.java:412) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:393) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:179) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157) java.net.SocketException: Malformed reply from SOCKS server java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:87) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:429) java.net.Socket.connect(Socket.java:519) oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141) oracle.net.nt.ConnOption.connect(ConnOption.java:123) oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337) oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422) oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672) oracle.net.ns.NSProtocol.connect(NSProtocol.java:237) oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042) oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301) oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531) oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221) oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503) oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207) oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:139) oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:88) oracle.jdbc.pool.OracleImplicitConnectionCache.makeCacheConnection(OracleImplicitConnectionCache.java:1583) oracle.jdbc.pool.OracleImplicitConnectionCache.makeOneConnection(OracleImplicitConnectionCache.java:515) oracle.jdbc.pool.OracleImplicitConnectionCache.defaultUserPrePopulateCache(OracleImplicitConnectionCache.java:222) oracle.jdbc.pool.OracleImplicitConnectionCache.<init>(OracleImplicitConnectionCache.java:198) oracle.jdbc.pool.OracleConnectionCacheManager.createCache(OracleConnectionCacheManager.java:298) oracle.jdbc.pool.OracleDataSource.cacheInitialize(OracleDataSource.java:412) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:393) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:179) oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)
The problem? The SOCKS proxy was configured to use our LAN web proxy. I went into Internet Options, turned the proxy off, and everything worked fine.