Using Java Applications and IDEs with Oracle Database Cloud Service (DBCS)
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
- 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.
2. Unblock the port 1521
- Download the 12.2.0.1 JDBC Thin driver (ojdbc8.jar) and 12.2.0.1 UCP (ucp.jar) or 12.1.0.2 JDBC Thin driver (ojdbc7.jar) and 12.1.0.2 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
DB_PASSWORD = "hr" or DB_URL = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST= )(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=PDB1. .oraclecloud.internal)))"; - Compile and Run a Java application:
[Windows]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.,
If you like the information, then share it. If anyone is working on JDBC CLOUD they will help.