javaoracle-databasenetbeansoracle-cloud-infrastructure

Can't connect to Autonomous Database | Oracle


I'm trying to connect to my Autonomous Database Oracle from java code in Netbeans. I have all the database configuration correctly written but for some reason I'm getting an error when establishing the connection.

This is my code to connect to the autonomous oracle database. For the user, I am using the admin that is created by default when the database is created:

        try{  
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con=DriverManager.getConnection(  
            "jdbc:oracle:thin:@my_hostname:my_port/service_name","admin","my_admin_password");  

        }catch (SQLException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

I have added the ojdbc10.jar and SDK17 to the project because the database version is 19c.

Network info about my database:

I have set my IP on the Access control list. I have mTLS not required so a wallet is not necessary to access. Using a wallet I do get access, I have tried it from the SQL extension of Visual Studio Code, but I don't want the wallet to be necessary. I have also tried opening input and output ports but it doesn't work.

This is the SQL error when executing the program:

Error de SQL: Error de E/S: Connection reset, Authentication lapse 0 ms.
java.sql.SQLRecoverableException: Error de E/S: Connection reset, Authentication lapse 0 ms.
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:927)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:820)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:80)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:820)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:624)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
    at example_ant.exampleClass.main(exampleClass.java:37)
Caused by: java.io.IOException: Connection reset, Authentication lapse 0 ms.
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:923)
    ... 7 more
Caused by: java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
    at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:187)
    at oracle.net.ns.NSProtocolNIO.doSocketRead(NSProtocolNIO.java:676)
    at oracle.net.ns.NIOPacket.readNIOPacket(NIOPacket.java:408)
    at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:143)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:353)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1706)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:631)
    ... 7 more

UPDATE

The problem was in how I was forming the db URL. I was forming it by concatenating the values of the parameters of the structure instead of directly copying the whole string from the tnsnames.ora file.

New URL: Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=my_port)(host=my_host))(connect_data=(service_name=my_service_name))(security=(ssl_server_dn_match=yes)))","user","password");


Solution

  • UPDATE

    The problem was in how I was forming the db URL. I was forming it by concatenating the values of the parameters of the structure instead of directly copying the whole string from the tnsnames.ora file.

    New URL: Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=my_port)(host=my_host))(connect_data=(service_name=my_service_name))(security=(ssl_server_dn_match=yes)))","user","password");