We are getting an error message when attempting to create an Oracle db connection from a java stored procedure running within an Oracle database. We have isolated to the connection and it is working with Oracle Database 12.1, running Java 1.7. Since upgrading to Oracle Database 12.2 and Java 1.8, we are getting the following error message.
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.RuntimeException: IO Error: The Network Adapter could not establish the connection
Attempting to connect with: jdbc:oracle:thin@########
An error occurred in ###: java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
Here is the code we are using to test the connection
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;
public class RemoteDBTest {
public static String remoteConnection()
throws SQLException
{
StringBuffer sb = new StringBuffer();
String userId = "xxxx";
String password = "xxxxx";
String url = "jdbc:oracle:thin:@server:port/SID"; // Destination is a remote database. Actual host, port, and service have been replaced in this example.
Connection conn = null;
OracleDataSource ods = new OracleDataSource();
ods.setUser(userId);
ods.setPassword(password);
ods.setURL(url);
System.out.println(url);
System.out.println(System.currentTimeMillis());
try {
conn = ods.getConnection();
} catch (Exception e){
System.out.println(System.currentTimeMillis());
throw e;
}
System.out.println(System.currentTimeMillis());
sb.append("Auto commit = " + conn.getAutoCommit());
conn.close();
return sb.toString();
}
public static void main(String[] args) {
try{
System.out.println(remoteConnection());
} catch (SQLException e){
e.printStackTrace();
}
}
}
The only functioning work around at this point from Oracle support is to set the property java.net.preferIPv4Stack
to true
, however, when set via code, it increases the execution time of the connection to 9 seconds. We have attempted to set this property via command line and the _JAVA_OPTIONS environment variable, however, it doesn't seem to affect the JVM running the stored procedure.
Any ideas or suggestions would be appreciated.
Host OS: Windows Server 2016
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Note: This is not a duplicate of IO Error: The Network Adapter could not establish the connection. Our connection parameters are correct and the connection is successful if we add System.setProperty("java.net.preferIPv4Stack" , "true");
to our code. However, as noted above, that introduces an unacceptable performance overhead.