Oracle 12c database connection using thin driver throws IO error

18,681

Maybe following comments could explain why you need the sevice name instead of the SID in the URL.

  • the Oracle JDBC FAQ mention that SIDs will be cease to be supported in one of the next few releases of the database

  • the Oracle JDBC devolopers guide mention Always connect to a service. Never use instance_name or SID because these do not direct to known good instances and SID is deprecated

  • the Oracle 2 day + Java developer tutorial mention the syntax jdbc:oracle:driver_type:[username/password]@//host_name:port_number:SID which seems to be a mixture of SID and service name URL (following the other documents and your working example)

  • in contrast the javadoc for OracleDriver mention only the SID syntax

  • the Oracle FAQ wiki mention both syntax

.

jdbc:oracle:thin:[USER/PASSWORD]@[HOST][:PORT]:SID
jdbc:oracle:thin:[USER/PASSWORD]@//[HOST][:PORT]/SERVICE
Share:
18,681
corporateWhore
Author by

corporateWhore

The sky's the limit when you hate your situation enough

Updated on July 31, 2022

Comments

  • corporateWhore
    corporateWhore almost 2 years

    I'm following the JDBC Developer's Guide and trying to test the JDBC thin driver connection using a short java program.

    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.jdbc.pool.OracleDataSource;
    class JDBCVersion
    {
    public static void main (String args[]) throws SQLException
    {
            OracleDataSource ods = new OracleDataSource();
            ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1522:orcl");
            Connection conn = ods.getConnection();
            // Create Oracle DatabaseMetaData object
            DatabaseMetaData meta = conn.getMetaData();
            // gets driver info:
            System.out.println("JDBC driver version is " + meta.getDriverVersion());
    }
    } //<host>:<port>:<service>
    

    I've tried every possible <host>:<port>:<service> combination but still get a java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

    I've successfully tested the OCI driver using another program included in the tutorial....but can't get this one to work. My application will be using the thin driver to connect to the database so my frustration level is....climbing.

    Any help is appreciated.

  • corporateWhore
    corporateWhore about 9 years
    Perfect, thank you for the information. I'm painfully new to database and am finding a lot of conflicting tutorials. I'm currently working through: JDBC Developer’s Guide 12c Release 1 (12.1)