Before You Begin
This 10-minute tutorial shows you how to connect an Oracle Java Cloud Service instance to an Oracle Cloud Infrastructure database.
Background
A data source is an object that enables a Java Database Connectivity (JDBC) client to obtain a database connection. The data source has a collection of database connections called a connection pool. An application can request a connection from the data source, use the connection to access the database, and then close the connection.
The data source does not close the connection, instead places it back in the connection pool to be used again. Oracle Java Cloud Service configures data sources when it provisions a new instance. You can add a data source to an existing instance by using the WebLogic Server Administration console. When the data source is deployed, the server creates database connections to fill the connection pool of its data source. For more information about data sources, see About Data Sources in Administering Oracle Java Cloud Service. This tutorial shows you how to provision an Oracle Database or PDB with any business data that your applications require.
What Do You Need?
- The required network, object storage, and security resources in the Oracle Cloud Infrastructure region where you intend to create the Oracle Java Cloud Service instance. See Creating the Infrastructure Resources Required for Oracle Platform Services
- A deployment of Oracle Database Cloud Service in the region where you created the Oracle Cloud Infrastructure resources. See Creating a Customized Database Deployment
- An Oracle Java Cloud Service instance in the same Oracle Cloud Infrastructure region and virtual cloud network (VCN) within the same or a different subnet as the Oracle Database Cloud Service deployment. See Creating an Oracle Java Cloud Service Instance on Oracle Cloud Infrastructure
- A deployment of Oracle Cloud Infrastructure Database system in the same VCN and within the same subnet as the Oracle Java Cloud Service instance. See To launch a DB system
- The name of the subnet, the name of the VCN, public IP address of the Oracle Java Cloud Service instance, public IP address of the Database system, and Database Unique Name on Oracle Cloud Infrastructure
Create
a Security List
Create a new security list with the stateless ingress rule to allow the incoming traffic from the Oracle Java Cloud Service instance to the Database System.
- Sign in to Oracle Cloud Infrastructure console. See Signing In to the Console.
- From the Oracle Cloud Infrastructure Console, click the Navigation menu
at the top left corner of the page, expand Core Infrastructure, go to Networking, and then click Virtual Cloud Networks.
- Click the cloud network in which you created Oracle Cloud Infrastructure Database.
- Click Security Lists.
- Click Create Security List.
- Enter the following:
- Create in Compartment: The compartment where you want to create the security list, if different from the compartment that you're currently working in.
- Security List Name: A name for the security list. For example, JDBAccess.
- Add one ingress rule in Allow Rules for Ingress:
- Select Stateless. By default, rules are stateful unless you specify otherwise.
- Enter the CIDR of the subnet to which the Oracle Java Cloud Service instance is attached, in Source CIDR.
- Select TCP in the IP Protocol dropdown list.
- Enter the port number of the database (1521) in Destination Port Range field.
- Delete the default (empty) egress rule to successfully create the security list.
- When you're done, click Create Security List.
- Add this new security list to the subnet that Oracle Cloud
Infrastructure Database is attached to.
- In the subnet that Oracle Cloud Infrastructure Database is attached to, click the Actions icon (three dots), and then select Edit.
- In the Security Lists section, click Add Security List, and then select the new security list that you created in the Security List drop-down list.
- Click Update.
Access
WebLogic Server
- Sign in to Oracle Cloud as the Java Administrator.
- From the Oracle Cloud Infrastructure console, click the Navigation
Drawer
icon at the top left corner of the page, expand Platform Services, and then select Java.
- From the Instances page, click the Manage this
Instance
icon next to the service instance, and then select Open WebLogic Server Administration Console.
- Sign in to the WebLogic console as the WebLogic Administrator. Enter the same WebLogic Administrator credentials that you specified when creating the service instance.
Create
a New JDBC Data Source
Create a new JDBC data source to establish a connection with the database system on Oracle Cloud Infrastructure.
- In the Change Center box at the top left corner of the page, click Lock & Edit.
- In the Domain Structure box, expand Services (by clicking the + next to it) and click Data Sources. The Summary of JDBC Data Sources page displays.
- Click New, and then select Generic
Data Source.
In the first page of the Create a New JDBC Data Source wizard, do the following:
- In Name: enter myNewDS.
- In JNDI Name: enter myNewDS.
- In the Database Type drop-down list, select Oracle.
- Click Next.
- In the second page of the wizard, do the following:
- In the Database Driver drop-down list, select *Oracle's Driver (Thin) for Service connections; Versions:Any.
- Click Next.
- In the third page of the wizard, retain all the default Transaction Options, and click Next.
- In the fourth page of the wizard, do the following:
- In the Database Name field, enter the
name in the following format:<dbservice.subnetname.dbvcn.oraclevcn.com>
The variables dbservice name is the Database Unique Name, subnetname is the name of the subnet, and dbvcn is the name of the Virtual Cloud Network. For example, DB_iad44r.sub06191912201.vcn0619191220.oraclevcn.com
- In the Host Name field, enter the public IP address of the Database system on Oracle Cloud Infrastructure
- In the Port field, enter 1521
- In the Database User Name field, enter sys as sysdba
- In the Password field, type the password for the database and retype the password in Confirm Password field.
- Click Next.
- In the fifth page of the wizard, click Test
Configuration to verify if a connection to the
database can be established based on the information that you
provided.
- If the connection test fails, click Back and review the entries that you made for the data source and correct any errors. If there are no errors in the entries and the test still fails, make sure that your database is running.
- If the message Connection test succeeded is displayed, click Next.
- In the last page of the wizard, select the target cluster for the JDBC data source in the Servers table and then click Finish.
- In the Change Center box at the top left corner of the page, click Activate Changes. "In the Summary of JDBC Data Sources page All changes have been activated. No restarts are necessary." message appears.
- In the Summary of JDBC Data Sources page, in the Data Sources table, the new data source, myNewDS, is listed.