Oracle Autonomous Database (ADB) is a family of products with each member of the family optimized by workload. Java applications require Java Key Store (JKS) or Oracle wallets to connect to ADB. The enhancements in JDBC driver in DB 19c and 18.3 make Java connectivity to ADB very simple. Follow the instructions to establish a successful connection to ADB.
Get access to the Oracle Autonomous Database (ADB). Click on these links to walk through the steps to provision an ADB instance if you have not provisioned an ADB instance already.
Remember the password that you used for ADMIN user. For this demo purpose, we will be using ADMIN user but, our recommendation is to create other database users either using SQLDeveloper or using SQL Developer web console.
tnsnames.ora and sqlnet.ora
: Network configuration files storing connect descriptors and SQL*Net client side configuration.cwallet.ora and ewallet.p12
: Auto-open SSO wallet and PKCS12 file. PKCS12 file is protected by the wallet password provided in the UI.keystore.jks and truststore.jks
: JKS Truststore and Keystore that is protected by the wallet passport provided while downloading the wallet.ojdbc.properties
: Contains the wallet related connection property required for JDBC connection. This should be in the same path as tnsnames.ora.Download JDK81 or higher JDK versions Note : If you are using JDK11, JDK10, or JDK9 then you don't need anything. If your JDK version is less than JDK8u162 then download the JCE Unlimited Strength Jurisdiction Policy Files. Refer to the README for installation notes.
1 Use "java -version" to check the JDK version that you have installed. Use "java -jar ojdbc8.jar" to check the JDBC driver version.
ojdbc8-full.tar.gz
and ojdbc10-full.tar.gz
contains oraclepki.jar, osdt_core.jar, and osdt_cert.jar
required for connecting to Autonomous database.
Note: If you are using older JDBC driver 12.2.0.1 or 12.1.0.2 then follow the instructions on this page to connect.
dbname_medium
found in tnsnames.ora
) as part of the connection string.
wallet_dbname.zip
is unzipped. TNS_ADMIN specifies the path of the wallet files, ojdbc.properties,
and tnsnames.ora
Example: DB_URL="jdbc:oracle:thin:@dbname_medium?TNS_ADMIN=/users/test/wallet_dbname/
"
Make sure to complete all the steps from pre-requisites section.
Wallet_dbname.zip.
. The zip file contains ojdbc.properties and tnsnames.ora. Uncomment the following JKS related connection properties in ojdbc.properties
file.
# Use the following properties to use JKS, comment out the oracle.net.wallet_location property above
# and set the correct password for both trustStorePassword and keyStorePassword.
# It's the password provided while downloading the wallet credentials from the DB Connection tab
oracle.net.ssl_server_dn_match=true
javax.net.ssl.trustStore=${TNS_ADMIN}/truststore.jks
javax.net.ssl.trustStorePassword=**password**
javax.net.ssl.keyStore=${TNS_ADMIN}/keystore.jks
javax.net.ssl.keyStorePassword=**password**
Note: Make sure to comment oracle wallets related property in ojdbc.properties
file
# Connection property for Oracle Wallets
# oracle.net.wallet_location=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=${TNS_ADMIN}))
Note: With 19c JDBC driver, you can use Easy Connect Plus and pass all the connection properties as name-value pair in the connection string. You can open the tnsnames.ora
and copy the hostname, servicename, and certificate details to form a connection string.
Example: jdbc:oracle:thin:@tcps://orclhostname:1522/orclservice?oracle.net.ssl_server_cert_dn=\"CN=test.uscom-east-1.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US\"
&javax.net.ssl.trustStore=/users/test/wallet_dbname/truststore.jks
&javax.net.ssl.trustStorePassword=**password**
&javax.net.ssl.keyStore=/users/test/wallet_dbname/keystore.jks
&javax.net.ssl.keyStorePassword=**password**
Compile the Java program Make sure to provide the correct path for the required jars in the classpath.
javac -classpath ./lib/ojdbc8.jar:./lib/ucp.jar UCPSample.java
Run the sample Java program Make sure to provide the correct path for the required jars in the classpath.
java -classpath ./lib/ojdbc8.jar:./lib/ucp.jar:. UCPSample
Make sure to complete all the steps from pre-requisites section.
ojdbc.properties.
oracle.net.wallet_location=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=${TNS_ADMIN}))
Note: With 19c JDBC driver, you can use Easy Connect Plus and pass all the connection properties as name-value pair in the connection string. You can open the tnsnames.ora
and copy the hostname, servicename, and certificate details to form a connection string etc.,
Example:.,jdbc:oracle:thin:@tcps://orclhostname:1522/orclservice?wallet_location=/users/test/wallet_dbname
&oracle.net.ssl_server_cert_dn=\"CN=adwc.uscom-east-1.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US\"
Compile the Java program Make sure to provide the correct path for the required jars in the classpath.
javac -classpath ./lib/ojdbc8.jar:./lib/ucp.jar:/lib/oraclepki.jar:./lib/osdt_core.jar:./lib/osdt_cert.jar UCPSample.java
Run the sample Java program Make sure to provide the correct path for the required jars in the classpath.
java -classpath ./lib/ojdbc8.jar:./lib/ucp.jar:/lib/oraclepki.jar:./lib/osdt_core.jar:./lib/osdt_cert.jar:. UCPSample
Make sure to complete all the steps from pre-requisites section.
Refer to the video Connecting to ATP or ADW using Tomcat for step by step instructions.
Copy contents of Tomcat_Servlet from Github to a directory /TOMCAT_HOME/webapps/UCPCloud. You can choose a different name for the application as well.
oraclepki.jar, osdt_core.jar, and osdt_cert.jar
in the same location.
<Context docBase="UCPCloud" path="/UCPCloud"
reloadable="true" source="org.eclipse.jst.jee.server:samplejdbcpage">
<Resource name="tomcat/UCP_atp" auth="Container"
factory="oracle.ucp.jdbc.PoolDataSourceImpl"
type="oracle.ucp.jdbc.PoolDataSource"
description="UCP Pool in Tomcat"
connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource"
minPoolSize="5"
maxPoolSize="50"
initialPoolSize="15"
user="jdbcuser"
password="XXXXXXXXXXX"
url="jdbc:oracle:thin:@jdbctest_medium?TNS_ADMIN=/Users/test/ATPTesting/wallet_JDBCTEST"
/>
</Context>
Start Tomcat server and invoke the servlet at http://lcoalhost:8080/UCPCloud/UCPServlet
Make sure to complete all the steps from pre-requisites section.
Refer to the video Connecting to ATP or ADW using Web Logic Server (WLS) for step by step instructions.
Copy the servlet from Github WebLogicServer_Servlet to your project.
jdbc:oracle:thin:@jdbctest_medium?TNS_ADMIN=/Users/test/ATPTesting/wallet_JDBCTEST
Start WebLogicServer and invoke the servlet at http://lcoalhost:7001/test-app/UCPServlet