Oracle Autonomous Database Jdbc Connect


Connecting to the Oracle ATP (or other autonomous database services) is pretty simple:

  • Download and unzip the database wallet file
  • Download the latest jdbc drivers from Oracle

Take a look for your service names in your tnsnames.ora file. Choose the service you want to connect with, in this example:

db202010241623_low = (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.eu-frankfurt-1.oraclecloud.com))(connect_data=(service_name=askjfhaslkjdfh45_db202010241623_low.adb.oraclecloud.com))(security=(ssl_server_cert_dn="CN=adwc.eucom-central-1.oraclecloud.com,OU=Oracle BMCS FRANKFURT,O=Oracle Corporation,L=Redwood City,ST=California,C=US")))

A list of predefined services and their characteristics for ATP can be found here.

  • Create JdbcSimpleApp.java, adapt the connectString, your username and password:

import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleConnection;

public class JdbcSimpleApp
{

    final static String connectString = "jdbc:oracle:thin:/@db202010241623_low?TNS_ADMIN=/path/to/your/unzipped/wallet";

    public static void main( String[] args ) throws SQLException
    {
        System.out.println( "Build datasource..." );

        OracleDataSource ods = new OracleDataSource();
        ods.setURL(connectString);
        ods.setUser("admin");
        ods.setPassword("your_top_secret_password");

        try (OracleConnection connection = (OracleConnection) ods.getConnection()) {

            // Do database stuff!
            connection.close();
          }
    }
}

Compile and run the code:

javac -cp ojdbc10-full/ojdbc10.jar JdbcSimpleApp.java
java  -cp ".:ojdbc10-full/ojdbc10.jar"  JdbcSimpleApp

(adapt your classpath to where your jdbc jars are, I used ojdbc10 but ojdbc8 should work equally)