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.
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
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
Download the 188.8.131.52 JDBC Thin driver (ojdbc8.jar) and 184.108.40.206 UCP (ucp.jar) or 220.127.116.11 JDBC Thin driver (ojdbc7.jar) and 18.104.22.168 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.
Example:DB_USER = "hr" or <Any user created>
Compile and Run a Java application:
java -cp .\lib\ojdbc7.jar;.\lib\ucp.jar
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.
(b) Login as "oracle" into the compute node.
(c) Connect to the database as a system user:
sqlplus sys as sysdba and enter the password chosen while creating the instance.
(d) Alter the session to use PDB:
alter session set container=pdb1;
(e) Unlock the user "hr":
alter user hr identified by hr account unlock;
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.,