Oracle by Example brandingConnect a Java EE Application to Oracle Database Cloud Service

section 0Before You Begin

This 15-minute tutorial shows you how to integrate two Oracle Cloud services, Oracle Application Container Cloud Service and Oracle Database Cloud Service, by using a Java Platform, Enterprise Edition (Java EE) application.

Background

Oracle Application Container Cloud Service provides a lightweight infrastructure so that you can run Java EE, Java Platform, Standard Edition (Java SE), PHP, Python, Node.js, and Ruby applications in Oracle Cloud. To develop more robust applications, you can integrate this cloud service with other Oracle services (for example, Oracle Database Cloud Service).

This tutorial provides source code for connecting a Java EE sample web application to Oracle Database Cloud Service by using a Java Database Connectivity (JDBC) data source. The application implements create, read, update, and delete operations for the EMPLOYEE table in the database.

What Do You Need?


section 1Set Up the Database

  1. Open Oracle SQL Developer.
  2. Click the View menu and select SSH.
  3. Right-click SSH Hosts and click New SSH Host.
  4. In the New SSH Host dialog box, enter or select the following values and click OK:
    • Name: DBCS
    • Host: The public IP address of your Oracle Database Cloud Service instance
    • Username: opc
    • Use key file (After you select this check box, click Browse, and select the private key file.)
    • Add a Local Port Forward (Select this check box.)
    • Name: Local
    • Host: localhost
    • Port: 1521
    • Use specific local port: 1523
    New SSH host window
    Description of the illustration new_ssh_hosts.png
  5. Right-click the DBCS host connection and select Connect.
  6. If it's required, enter the passphrase.
  7. Right-click Connections and select New Connection.
  8. In the New / Select Database Connection dialog box, enter or select the following values and click Test:
    • Connection Name: Your connection name
    • Username: Your database user name
    • Password: Your database password
    • Connection Type: SSH
    • Role: default
    • Port forward: Local (DBCS)
    • Service name: PDB1.<your-identity-domain>.oraclecloud.internal

      Note: Keep the default values for the rest of the fields.

  9. Click Save and then Connect.
  10. Right-click the connection and select Open SQL worksheet.
  11. To create the EMPLOYEE table and the EMPLOYEE_SEQ sequence, copy the following script into the SQL worksheet:
    CREATE TABLE EMPLOYEE (
          ID INTEGER NOT NULL,
          FIRSTNAME VARCHAR(255),
          LASTNAME VARCHAR(255),
          EMAIL VARCHAR(255),
          BIRTHDATE VARCHAR(10),
          TITLE VARCHAR(255),
          DEPARTMENT VARCHAR(255),
          PRIMARY KEY (ID)
    	  ); 
    
    CREATE SEQUENCE EMPLOYEE_SEQ
     START WITH     100
     INCREMENT BY   1;  
  12. Click Run Script Run Script button and then click Commit Commit button.

section 2Deploy Your Application to Oracle Application Container Cloud Service

  1. Extract the contents of the employees-app-dbcs.zip file to your local system.
  2. Open the Oracle Application Container Cloud Service console.
  3. In the Oracle Cloud My Services dashboard, click Action Action menu icon and select Oracle Application Container Cloud Service.
  4. In the Create Application dialog box, in the Applications list view, click Create Application and select Java EE.
  5. In the Application section, enter EmployeeApplication for the name of your application and click Browse.
  6. In the File Upload dialog box, select the employees-app.war from the employees-app-dbcs/target directory and click Open.
  7. If your account has access to Oracle Cloud Infrastructure regions, in the Region field select the same region that you used to create your Oracle Database Cloud Service instance.
  8. Keep the default values in the Instances and Memory fields and click Create.

section 3Add the Service Binding and the JNDI Name

  1. After the application is created, on the Applications tab, click EmployeeApplication.
  2. Click the Deployments tab. In the Service Binding section, click Add.
  3. In the Add Service Binding dialog box, enter or select the following values and click Save:
    • Service Type: Oracle Database Cloud Service
    • Service Name: Your service name
    • Username: Your database user name
    • Password: Your password
  4. In the Oracle Database Cloud Service binding, click Add Add Service Mapping Property.
  5. In the Add Service Binding Property dialog box, select JNDI Name for Name, enter jdbc/testds for Value, and then click Save.
  6. In the Deployments dialog box, click Apply Edits.

section 4Test the Application

  1. After the application restarts, click the URL for your application.
    Deployments dialog box
    Description of the illustration employee_app_response.png
  2. Click New Employee, enter values in the Name, Last name, Birthdate, Role, Department, and E-mail fields, and click Accept.
  3. Click the ID number, update the employee information, and click Accept.
  4. To delete the employee, click Delete button.

more informationWant to Learn More?