0

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.

Kent Anderson
  • 486
  • 2
  • 16
  • @Abra Yes, it is a java stored procedure. It is not pl/sql. – Kent Anderson Aug 18 '20 at 18:45
  • @Abra There you go – Kent Anderson Aug 18 '20 at 19:47
  • @Abra - The question reads, `We are getting an error message when attempting to create an Oracle db connection from Java code...`. – Arvind Kumar Avinash Aug 18 '20 at 21:26
  • @KentAnderson - As per the [documentation](https://docs.oracle.com/javase/8/docs/technotes/guides/net/ipv6_guide/): `If IPv6 is available on the operating system, the underlying native socket will be an IPv6 socket. This allows Java applications to connect to, and accept connections from, both IPv4 and IPv6 hosts. If an application has a preference to only use IPv4 sockets, then this property can be set to true. The implication is that the application will not be able to communicate with IPv6 hosts.` – Arvind Kumar Avinash Aug 18 '20 at 21:39
  • @KentAnderson - You may find [this page](https://docs.oracle.com/cd/E27119_01/doc.11113/e23126/installationandupgradeguideprintable36.html), [this page](https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/JDBC-troubleshooting.html#GUID-5BC8E69F-F199-468C-8AB8-72D489F33029) and [this page](https://docs.oracle.com/en/middleware/fusion-middleware/weblogic-server/12.2.1.3/wlsrn/issues.html#GUID-A42A4025-4B26-485A-9BB5-BF36541ABD60) useful as well. – Arvind Kumar Avinash Aug 18 '20 at 21:49
  • @KentAnderson - As per your edit, [IO Error: The Network Adapter could not establish the connection](https://stackoverflow.com/questions/12574414/io-error-the-network-adapter-could-not-establish-the-connection) doesn't answer your question. Therefore, I've opened the question again. – Arvind Kumar Avinash Aug 18 '20 at 21:53
  • Why do you need to connect to another Oracle database from a java stored procedure? There are several ways for two Oracle instances to communicate, for example there is [database link](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/CREATE-DATABASE-LINK.html#GUID-D966642A-B19E-449D-9968-1121AF06D793). Is using a java stored procedure your only option? – Abra Aug 19 '20 at 05:01
  • Perhaps [Advanced Queuing](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/adque/index.html) is a possible option? – Abra Aug 19 '20 at 05:08
  • @Abra Thank you for the suggestions and help. Unfortunately, we have a significant amount of existing code using this type of connection. – Kent Anderson Aug 19 '20 at 14:52

1 Answers1

0

Most likely you are using wrong URL "jdbc:oracle:thin:@server:port/SID"

Shall be jdbc:oracle:thin:@serverhostname.com:1521/DB

@serverhostname.com hostname of oracle db 1521 is a port of your Db (1521 is default I think) SID - DB shall be a SID of your database (ask your DB admin for correct one)

Vlad Ulshin
  • 482
  • 2
  • 5
  • We are using the correct hostname, port, and database identifier. I used those values as placeholders in my posted code for privacy reasons. – Kent Anderson Aug 18 '20 at 20:42