Access the Oracle Database Cloud Service from Java SE applications, Java Web applications (i.e., Servlets) and Java EE containers using the Oracle JDBC and the Universal Connection Pool (UCP). The following steps will allow a successful connection.
1. Create a Database Instance on Oracle Cloud
If you already have a database instance created then you can skip this step. Otherwise, create a new database instance by following these steps.
After you sign up for Oracle Cloud, login to your account (http://cloud.oracle.com). On the Dashboard, you will find Create Instance" button. Click that button and follow the steps to create a database instance.
Another way to create an instance is to choose Database from the Dashboard and use Open Service Console that lists all the database services. Create a new instance by clicking on "Create Service" button. Check out the Fig.1: Oracle Database Service Console
Once the database instance is created, you can click on the new instance created to get the database details. For example., Click on "dev" as shown in Fig.1:Oracle Database Service Console
The HOST or the IP address can be obtained by viewing detailed information of a database instance.
The SERVICE_NAME is also present in the detailed information section. The format of the database service name is pdb.identity-domain.oraclecloud.internal
2. Unblock the port 1521
- Oracle Database Cloud Service support access to Oracle Database on the standard Oracle Net Listener port (1521). When a database instance is first created, the Oracle Net Listener port (1521) is blocked to ensure network security. Unblock this port by choosing "Access Rules" as shown in Fig.1:Oracle Database Service Console and choose 1521 the port used by SQL*Net to enable.
Fig.1: Oracle Database Service Console
3. Compile and Run Your Simple Java Application
- Download the 126.96.36.199 JDBC Thin driver (ojdbc8.jar) and 188.8.131.52 UCP (ucp.jar) or 184.108.40.206 JDBC Thin driver (ojdbc7.jar) and 220.127.116.11 UCP (ucp.jar) to a location and add that location to the classpath.
Set the connection string according to your environment as illustrated below. For example., you may use the HR schema which is available by default.
DB_USER = "hr" or <Any user created>
DB_PASSWORD = "hr" or <password chosen while creating a user>
DB_URL = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=<public IP address>)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=PDB1.<identity-domain>.oraclecloud.internal)))";
- Compile and Run a Java application:
java -cp .\lib\ojdbc7.jar;.\lib\ucp.jar UCPSample
TroubleShooting Tip: When the database instance is first created, HR user is locked for security reasons. You will receive an error "account locked". So, unlock the HR user using these steps before using it to connect to the database.
- SSH to the compute node of the database
- Login as "oracle" into the compute node.
- Connect to the database as a system user:
sqlplus sys as sysdba and enter the password chosen while creating the instance.
- Alter the session to use PDB:
alter session set container=pdb1;
- Unlock the user "hr":
alter user hr identified by hr account unlock;
4. Connect to Compute Node using SSH tunnel
You can connect to the compute node where the database instance is running through a SSH tunnel. Follow the instructions described in the chapter Creating an SSH Tunnel to a Compute Node Port . After connecting, you can access the database and create new users, change database user password etc.,
Database Cloud Service Resources
Help Center | User Guide | What's New | Troubleshooting Tips - Manuals
Other Developer Resources
JDBC and UCP Landing Page - for Whitepapers, Javadoc, Forum etc.,