Configuring JDBC Data Sources

Purpose

This tutorial explains the steps to configure Data Sources for an Oracle WebLogic Server Instance. After completing this tutorial, you should be to:

 Create a JDBC data source
 Locate a JDBC data source in a server's Java Naming and Directory Interface (JNDI) tree
 Test the use of JDBC data source using a simple web application

Time to Complete

Approximately 30 minutes

Topics

This OBE tutorial covers the following topics:

 Overview
 Scenario
 Setting up the schema in Oracle Database
 Starting up Oracle WebLogic Server instance
 Configuring a JDBC Data Source
 Testing the Data Source using a simple Web application
 Summary
 Related information

Viewing Screenshots

 Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: Because this action loads all screenshots simultaneously, response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over each individual icon in the following steps to load and view only the screenshot associated with that step.

The screenshots are provided to give you an idea of how to configure and administer specific functionality in Oracle WebLogic Server and may not reflect the specific environment that you are using.

Overview

A data source object enables a Java Database Connectivity (JDBC) client to obtain a DBMS connection from a JDBC pool. The connection pool within a JDBC data source contains a group of JDBC connections that applications reserve, use, and then release to the pool. The connection pool and the connections within it are created when the connection pool is registered. The connections pool is usually registered when starting up WebLogic Server or when deploying the data source to a new target.
In this OBE you will create a dizzyworldDS data source to connect to an Oracle Database .

Back to Topic List

Scenario

You are an application server administrator in the Dizzyworld Corporation. You have installed and configured Oracle WebLogic Server for your enterprise. For information on how to install and configure Oracle WebLogic Server, please refer to these OBEs:

 Installing and Configuring Oracle WebLogic Server
 Configuring Oracle WebLogic Server Managed Instances

The system architects at Dizzyworld have decided to create dizzyworldDS data source object to connect to HRDATA in an Oracle Database. The data sources and their connection pools provide better connection management and help to keep the system running with better performance.

Prerequisites

Before you start the tasks, make sure that your system environment meets the following requirements:

Prerequisite Tutorials:

Before starting this tutorial, you should complete the following prerequisite tutorials:

Installing and Configuring Oracle WebLogic Server

 Configuring Oracle WebLogic Server Managed Instances

Minimum Hardware Requirements

Item Specification
Processor Speed 1 GHz
Memory 2 GB
Free Hard Disk Space 1 GB

Software Requirements

The system should have installed the following products:

Oracle WebLogic Server

 Oracle Database 10g or higher

Download Required Files

Download the necessary Conf_JDBC_OBE.zip and save it on your machine where you would be performing the tasks. Extract the content into your local drive. In this sample, the files are extracted into the /home/oracle/labs/wls103/testds folder. The extract contains three files:

  File Name Description
1. testds_oracle.sql A SQL script file to configure the required schema in Oracle Database.
2. testds.war A simple Web application file used for testing the configured data source.
3. deploy_testds.py A WLST script used for deploying the Web application.

Back to Topic List

 

Setting up the Schema in Oracle Database

1.

Login to the system as the user that started the Oracle Database. Invoke a shell window and navigate to the location where you have downloaded the script:

$ cd /home/oracle/labs/wls103/testds

 

2.

Set up the database environment variables using the the following export shell command .

$ export ORACLE_SID=inf01
$ export ORACLE_HOME=/u01/app/oracle/product/10g/inf01

 

3.

IInvoke SQL Plus as sysdba user:

$ $ORACLE_HOME/bin/sqlplus / as sysdba .

 

4.

Then run the testds_oracle.sql script to create the necessary schema. This creates a schema named PBPUBLIC with three tables and populates the tables with a few rows.

SQL> @testds_oracle.sql


 

Back to Topic List

Starting up Oracle WebLogic Server instance

The basic domain in this case consists of an Administration Server and a Managed Server (dizzy1). To start the two servers, perform the following steps:

1.

Invoke a new shell window and navigate to the bin subfolder under the folder where you have configured the domain For example:

$ cd / u01/app/oracle/product/Middleware/user_projects/domains/dizzyworld/bin .

 

2.

Run the startWebLogic.sh script to start the Administration Server.

 

3.

When prompted :with “ Enter username to boot WebLogic server”, enter the administrative user name you have setup when you created the domain. In this case user name “admin” is shown. Then enter the password for admin user when prompted with “ Enter password to boot WebLogic server”.

 

4.

This will start the Administration Server. Leave this shell window running.

 

5.

To start the Managed Server (dizzy1) in the domain, invoke another shell window.

 

 

6.

Navigate to bin subfolder in your domain and execute the following command: to start the managed server.

$ ./startManagedWebLogic.sh dizzy1 http://localhost:7001

 

7.

When prompted :with “ Enter username to boot WebLogic server”, enter the administrative user name you have setup when you created the domain. In this case user name “admin” is shown. Then enter the password for admin user when prompted with “ Enter password to boot WebLogic server”.

 

 

8.

This would start up the Managed Server. Again, leave this window as it is..

 

Back to Topic List

Configuring a JDBC Data Source

1.

Open a Web browser and navigate to http://localhost:7001/console. Log in as
admin with welcome1 as the password.

2.

Navigate to Data Sources page using dizzyworld > Services > JDBC à Data Sources .

 

3.

When Summary of JDBC Data Sources page appears, click Lock & Edit in the Change Center to initiate configuration of data source.

 

4.

In the Summary of JDBC Data Sources page, click New under the Data Sources table.

 

5.

Specify the following properties for configuring a JDBC data source and click Next.

 Name dizzyworldDS
 JNDI Name dizzyworldDS
 Database Type Oracle
 Database Driver BEA’s Oracle Driver(Type 4) Versions:9.0.1,9..2,0.10,11
  Note: Do not select the Type 4 XA driver

 

6.

In the Transaction Options page, keep the default options and click Next

 

7.

Specify the database connection properties (in this case we use the following data) and click Next

 Database Name inf01
 Host Name localhost
 Port 1521
 Database User Name PBPUBLIC
 Password PBPUBLIC

 

8.

Click Test Configuration to check if the connection to the Database is working, and then click Next.

 

9.

In the Select Targets table, select dizzy1 and click Finish.

 

10.

Click dizzyworldDS under the Data Sources table on the Summary of JDBC Data Sources page .

 

11.

Click the Configuration > Connection Pool tab

 

12.

Specify any connection pool parameters such as those described here, and click Save.

 Initial Capacity 5
 Maximum Capacity 15
 Capacity Increment 5

 

13.

The configuration settings are saved. In the Change Center, click Activate Changes to effect your changes

The changes are effected to the server, and an appropriate message appears.

 

14.

Navigate to dizzy1 managed server instance and click View JNDI Tree.

 

15.

The JNDI Tree appears in a separate tab. Notice that dizzyworldDS appears in the JNDI structure.

 

Back to Topic List

Testing JDBC Data Source Using Simple Web Application

1.

Open a new shell window, navigate to the folder where you have the testds.war application (for example: /home/labs/wls103/testds folder).

 

2.

Set the WL_HOME environment variable to point to the location where you have installed WLS 10.3..

 

3.

Run WL_HOME/server/bin/setWLSEnv.sh script to set up the environment variables.

 

4.

Run the command java weblogic.WLST deploy_testds.py to deploy the testds.war application..

 

5.

Open a Web browser and navigate to http://localhost:7003/testds/testdatasource.jsp to test the data source. Enter the administrative username and the corresponding password and click Test Data Source.

 

6.

The data is displayed from Employee table.

 

Back to Topic List

Summary

In this tutorial, you learned how to:

 Set up the schema in Oracle Database
 Start up Oracle WebLogic Server instances
 Configure a JDBC Data Source
 Test the Data Source using a simple Web application

 

Related Information

 To ask a question about this OBE tutorial, post a query on the OBE Discussion Forum.

Back to Topic List

 Place the cursor over this icon to hide all screenshots.

 

 

 

Left Curve
Popular Downloads
Right Curve
Untitled Document