Try connecting to the Autonomous Database with JDK6 (Java) + JDBC OCI Driver (type 2).

Therefore, try connecting to the Autonomous Database with JDK6 (Java) + JDBC OCI Driver (type 2).

1. Download and unzip Oracle Instant Client 12.1.0.2

Download the Oracle Instant Client. Download the 12.1.0.2 Instant Client that contains ojdbc6.jar for JDK6.

  • Instant Client Downloads for Linux x86-64 (64-bit)
    https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
    instantclient-basic-linux.x64-12.1.0.2.0.zip
    instantclient-jdbc-linux.x64-12.1.0.2.0.zip

This time, it is assumed that it is expanded to / home / opc / work / instantclient_12_1 /.

unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
unzip instantclient-jdbc-linux.x64-12.1.0.2.0.zip
ls -la /home/opc/work/instantclient_12_1/
total 192020
drwxrwxr-x. 2 opc opc      4096 Jul 20 10:41 .
drwxrwxr-x. 7 opc opc      4096 Jul 21 12:55 ..
-rwxrwxr-x. 1 opc opc     29404 Jul  7  2014 adrci
:
-r-xr-xr-x. 1 opc opc    156353 Jul  7  2014 libocijdbc12.so
-r-xr-xr-x. 1 opc opc    337137 Jul  7  2014 libons.so
-rwxrwxr-x. 1 opc opc    118491 Jul  7  2014 liboramysql12.so
-r--r--r--. 1 opc opc   3692096 Jul  7  2014 ojdbc6.jar
-r--r--r--. 1 opc opc   3698857 Jul  7  2014 ojdbc7.jar
-r--r--r--. 1 opc opc   1659574 Jul  7  2014 orai18n.jar
-r--r--r--. 1 opc opc     87292 Jul  7  2014 orai18n-mapping.jar
-rwxrwxr-x. 1 opc opc    227410 Jul  7  2014 uidrvci
-rw-rw-r--. 1 opc opc     71202 Jul  7  2014 xstreams.jar

2. Download and unzip the Autonomous Database wallet

Download and unzip the Autonomous Database wallet. Please refer to the following articles.

  • Connect to an autonomous database (Autonomous Transaction Processing) using Golang https://qiita.com/sugimount/items/69e11c116a895c9feb97
cd /home/opc/work/wallet
unzip Wallet_DBxxxxxxxxxxxxxx.zip
ls -la
total 68
drwxrwxr-x. 2 opc opc  4096 Jul 21 13:36 .
drwxrwxr-x. 6 opc opc  4096 Jul 21 13:36 ..
-rw-rw-r--. 1 opc opc  6661 Jun 24 10:18 cwallet.sso
-rw-rw-r--. 1 opc opc  6616 Jun 24 10:18 ewallet.p12
-rw-rw-r--. 1 opc opc  3242 Jun 24 10:18 keystore.jks
-rw-rw-r--. 1 opc opc    87 Jun 24 10:18 ojdbc.properties
-rw-rw-r--. 1 opc opc   114 Jun 24 10:18 sqlnet.ora
-rw-rw-r--. 1 opc opc  5638 Jun 24 10:18 tnsnames.ora
-rw-rw-r--. 1 opc opc  3336 Jun 24 10:18 truststore.jks
-rw-rw-r--. 1 opc opc 19912 Jun 24 10:18 Wallet_DBxxxxxxxx.zip

3. Edit sqlnet.ora in the Autonomous Database wallet

Unzipping the wallet will generate sqlnet.ora, but rewrite the DIRECTORY of this sqlnet.ora to the unzipped directory of the wallet.

WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="?/network/admin")))
↓
WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="/home/opc/work/wallet")))

4. Sample code for testing

It's a miscellaneous code that hasn't released resources in finally, but forgive me Clemens ……: (; ゚'ω ゚'): You can't use the try-with-resources syntax with JDK6. 彡 (゜) (゜)

import java.sql.*;

public class GetContainerName {
    public static void main(String[] args) {
        final String path = "jdbc:oracle:oci:@dbxxxxxxxx_tp";
        final String id = "ADMIN";  //ID
        final String pw = "xxxxxxxx";  //password

        try {
            Connection conn = DriverManager.getConnection(path, id, pw);
            Statement  stmt = conn.createStatement();
            ResultSet  rs   = stmt.executeQuery("SELECT NAME FROM V$CONTAINERS");
            while (rs.next()) {
                String cn = rs.getString("name");
                System.out.println("Container Name => " + cn);
            }
        } catch(SQLException ex) {
            ex.printStackTrace();  //Error
        }
    }
}

The point is to specify the connection string of tnsnames.ora while specifying the JDBC URL here and the oci driver.

final String path = "jdbc:oracle:oci:@dbxxxxxxxx_tp";

5. Compile and run code

Compile and run with javac. Specify the following environment variables at the time of execution.

  • LD_LIBRARY_PATH
    ⇒ Specify the directory where you extracted the Oracle Instant Client.
  • TNS_ADMIN
    ⇒ Specify the directory where the wallet of Autonomous Database is expanded.

The execution command is as follows.

export JAVA_HOME=/usr/java/jdk1.6.0_211
export PATH=${JAVA_HOME}/bin:${PATH}
java -version
javac -version
javac GetContainerName.java
export LD_LIBRARY_PATH=/home/opc/work/instantclient_12_1:$LD_LIBRARY_PATH
export TNS_ADMIN=/home/opc/work/wallet
java -classpath /home/opc/work/instantclient_12_1/ojdbc6.jar:. GetContainerName

The execution result is as follows, it worked well! 彡 (^) (^)

$ export JAVA_HOME=/usr/java/jdk1.6.0_211
$ export PATH=${JAVA_HOME}/bin:${PATH}
$ java -version
java version "1.6.0_211"
Java(TM) SE Runtime Environment (build 1.6.0_211-b11)
Java HotSpot(TM) 64-Bit Server VM (build 20.211-b11, mixed mode)
$ javac -version
javac 1.6.0_211
$ javac GetContainerName.java
$ export LD_LIBRARY_PATH=/home/opc/work/instantclient_12_1:$LD_LIBRARY_PATH
$ export TNS_ADMIN=/home/opc/work/wallet
java -classpath /home/opc/work/instantclient_12_1/ojdbc6.jar:. GetContainerName

Container Name => VRWV9351YZ4NXNS_DB201906031608

6. Reference document

  • Connection using JDBC-OCI driver using Wallets https://www.oracle.com/technetwork/database/application-development/jdbc-eecloud-3089380.html#jdbcoci

  • What is the relationship between the release of Oracle JDBC and the version of JDK? https://www.oracle.com/technetwork/jp/database/application-development/jdbc/overview/default-090281-ja.html#01_03_1

  • Oracle JDBC Driver Getting Started Guide-Installation, Certification, etc. (Document ID 1999901.1) * Login required https://support.oracle.com/epmos/faces/DocumentDisplay?id=1999901.1

Supplement. Is it possible to connect with the Thin Driver?

Autonomous Database needs to communicate with TLSv1.2, it is standard equipment in JDK8 or later, patch for back port is provided in JDK7, but it seems that this backport is not provided in ~~ JDK6 Is it going to be painful? ~~ 彡 (゚) (゚)

  • JDBC Thin Connections and Wallets
    https://docs.oracle.com/en/cloud/paas/autonomous-data-warehouse-cloud/user/connect-jdbc-thin-wallet.html#GUID-5ED3C08C-1A84-4E5A-B07A-A5114951AA9E

Autonomous Data Warehouse mandates a secure connection that uses Transport Layer Security (TLSv1.2).

  • Software requirements for connectivity using JDBC Thin and UCP https://docs.oracle.com/cd/E83857_01/paas/atp-cloud/atpug/connecting-jdbc-thin-driver.html#GUID-EEB8AC2B-AE63-486A-A7DB-96460DCA881E

Download the patched 12.1.0.2 JDBC Thin driver (ojdbc7.jar) and 12.1.0.2 UCP (ucp.jar) and add their location to your classpath.

  • Doc ID 2122800.1 "IO Error: No appropriate protocol" When Trying to Connect to Oracle Database 12.1 with TLSv1.1 and TLSv1.2 Protocols * Login required https://support.oracle.com/epmos/faces/DocumentDisplay?id=2122800.1

(Addition) It was confirmed below that it is possible to connect with JDK6 + JDBC Thin Driver 12.1.0.2. Please refer to those who have a support contract.

  • Download and install JDK6 u211 (JDK6 u181 or later) from Doc ID 1534791.1
  • Install Oracle Client (* not Instant) 12.1.0.2
  • Apply PSU 12.1.0.2.20190716 (Patch 29494060) to Oracle Client
  • Apply individual patch 23176395 (* Merged version of 204 26934, 19030178, 19154304) to Oracle Client
  • Apply individual patch 25797943 (* 12.1.0.2 version selected) to Oracle Client
  • Connect by specifying the JDBC Driver (ojdbc6.jar) and various jars under the Oracle Client to which the backport by Patch is applied.

The reference information is as follows.

  • Java SE and JRockit Archived Downloads on MOS for Java Versions that Have Reached EOL (Doc ID 1534791.1)
    https://support.oracle.com/epmos/faces/DocumentDisplay?id=1534791.1
  • JDBC TLS Connections Fail with java.io.EOFException: SSL peer shut down incorrectly After Patching the Database With APRIL 2018 PSU + TLS 1.2 Patch:28362304 (Doc ID 2477104.1)
    https://support.oracle.com/epmos/faces/DocumentDisplay?id=2477104.1
  • JDBC Thin Driver receives "java.security.NoSuchAlgorithmException: SSO KeyStore not available" (Doc ID 2321763.1)
    https://support.oracle.com/epmos/faces/DocumentDisplay?id=2321763.1
  • "IO Error: No appropriate protocol" When Trying to Connect to Oracle Database 12.1 with TLSv1.1 and TLSv1.2 Protocols (Document ID 2122800.1) https://support.oracle.com/epmos/faces/DocumentDisplay?id=2122800.1
  • Java SE 6 Advanced and Java SE 6 Support (formerly known as Java SE for Business 6) Release Notes
    https://www.oracle.com/technetwork/java/javase/downloads/overview-156328.html#R160_181
    ⇒ (6u181)The SHA224withDSA and SHA256withDSA algorithms are now supported in the TLS 1.2
  • How To Configure Oracle JDBC Thin Driver To Connect To Database Using TLS v1.2 (Document ID 2436911.1) https://support.oracle.com/epmos/faces/DocumentDisplay?id=2436911.1

Recommended Posts

Try connecting to the Autonomous Database with JDK6 (Java) + JDBC OCI Driver (type 2).
Try connecting to the OCI Database (DBaaS) PDB with Java's JDBC Thin Driver. (Oracle Cloud Infrastructure)
Try connecting to Autonomous DB (ADW / ATP) with Java's JDBC Thin Driver. (OCI, Oracle Cloud Infrastructure)
I tried connecting to Oracle Autonomous Database 21c with JDBC Thin
Connecting to a database with Java (Part 1) Maybe the basic method
Try connecting to AzureCosmosDB Emulator for Docker with Java
[JDBC] I tried to access the SQLite3 database from Java.
Sample code to get key JDBC type values in Java + H2 Database
Try using the Wii remote with Java
Try to link Ruby and Java with Dapr
Try to implement TCP / IP + NIO with JAVA
[Java / PostgreSQL] Connect the WEB application to the database
[Java] Try to solve the Fizz Buzz problem
Try to summarize the common layout with rails
Summary of how to use the proxy set in IE when connecting with Java
Settings for connecting to MySQL with Spring Boot + Spring JDBC
Organized how to interact with the JDK in stages
HTTPS connection with Java to the self-signed certificate server
I want to return a type different from the input element with Java8 StreamAPI reduce ()
[Java] Change the process according to the situation with the Strategy pattern
Find the address class and address type from the IP address with Java
[Beginner] Try to make a simple RPG game with Java ①
Initialization with an empty string to an instance of Java String type
[Java] To know the type information of type parameters at runtime
Be sure to compare the result of Java compareTo with 0
How to deal with the type that I thought about writing a Java program for 2 years
Read the data of Shizuoka point cloud DB with Java and try to detect the tree height.