javasqljdbcoracle12cojdbc

Oracle 12c database connection using thin driver throws IO error


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.


Solution

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

    .

    jdbc:oracle:thin:[USER/PASSWORD]@[HOST][:PORT]:SID
    jdbc:oracle:thin:[USER/PASSWORD]@//[HOST][:PORT]/SERVICE