You are on page 1of 24

9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

Oracle WebLogic Server 12c: Configuring a


JDBC Data Source

Before You Begin

Purpose

This tutorial shows how to use the Oracle WebLogic Server 12c administration console to configure a JDBC data
source.

Time to Complete

Approximately 1/2 hour

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. Rather than actually close the connection, however, the data source places it back in the connection
pool to be used again. Data sources can be created as part of the configuration of an instance of WebLogic
Server. When that server comes up, (or the data source is deployed), the server creates database connections to
fill the connection pool of its data source.

Scenario

This tutorial covers using the Oracle WebLogic Server 12c (12.2.1) administration console to create a data
source and its connection pool. The connections are to an Oracle Database.

Context

Before starting this tutorial, you should have completed the Oracle by Example tutorials titled Oracle WebLogic
Server 12c: Installing WebLogic Server and Creating a Domain and Oracle WebLogic Server 12c:
Configuring Managed Servers.

What Do You Need?

The following is a list of software requirements:


http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 1/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

Oracle WebLogic Server 12c (12.2.1)

Oracle Database 12c or later (Express Edition may work as well but has not been tested.
Note: In this tutorial Oracle Database XE 11.2 is used.

Setting Up the Schema in the Oracle Database

To set up the database schema required by the JDBC client application, perform the following steps:

1. Download the jdbc_obe.zip (files/jdbc_obe.zip) file to the machine where your WebLogic Server domain and
servers are. Extract the file contents to a local drive. In this tutorial, the files are extracted into the
/u01/jdbc_obe/testds directory. The zip file contains three files:

testds_oracle.sql
A SQL script to configure the required schema in the Oracle Database
testds.war
A simple web application used to test the configured data source
deploy_testds.py
A WebLogic Scripting Tool (WLST) script used to deploy the web application

2. Log in to the system as the user that started the Oracle Database. Open a Terminal window and navigate to
the location of the SQL script file, testds_oracle.sql . In this tutorial that is:

cd /u01/jdbc_obe/testds

3. Make sure that the database environment variables are set by printing them out:

echo $ORACLE_HOME
/u01/app/oracle/product/12.1.0/dbhome 1
echo $ORACLE_SID
orcl

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 2/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

Note: The values of your environment variables may be different. If there are no values printed, then set the
variables to the proper values with:

export ORACLE_HOME=<valid_value>
export ORACLE_SID=<valid_value>

4. Then invoke SQL Plus as the sysdba user:

$ORACLE_HOME/bin/sqlplus / as sysdba

5. Connect to the database as the system user. You can give the password and the name of the database as
you connect. In this tutorial the command is:

connect system/welcome1 as sysdba

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 3/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

6. Then run the SQL script with this command:

@testds_oracle.sql

The script, testds_oracle.sql , creates a user called DBTESTER with the password welcome1 . It grants
that user the abilities to create sessions, tables, and so on. It then connects to the database as that user and
creates three tables: EMPLOYEE , WLS_CATALOG_ITEMS , and WLS_CLIENT_INFO . Finally, it inserts rows into
those tables and exits.

Starting WebLogic Server

To start the administration server and the server1 managed server of the domain, perform the following steps:

1. If Node Manager is not already running, it needs to be started. To start it, in a Terminal window, navigate to the
domain directory, and enter the command:

./startNodeManager.sh

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 4/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

2. If the administration server of the domain is not already running, it needs to be started. To start it, in another
Terminal window, navigate to the domain directory, then cd into the bin subdirectory. Enter the command:

./startWebLogic.sh

3. The managed server server1 should also be running. If it is not already running, start it. In another Terminal
window, navigate to the domain directory, then cd into the bin subdirectory. Note: Use the host name and
port of the administration server of your domain. Enter the command:

./startManagedWebLogic.sh server1 http://localhost:7001

This runs the script to start the managed server named server1 . Also notice the argument that gives the
URL of the domain's administration server:
http://localhost:7001 .

4. When prompted for a username and password, enter the credentials of the domain administrator.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 5/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

Configuring a JDBC Data Source

To configure a JDBC data source by using the WebLogic Server administration console, perform the following
steps:

1. After the servers are up and running, access the WebLogic Server administration console. Open a web
browser and enter its URL:
http://<hostname>:<port>/console

In this tutorial, that is: http://localhost:7001/console

Note: Use the host name and port of the administration server of your domain.

2. On the Welcome screen, log in using the Username and Password entered to start the servers.

3. Creating a data source is a change to the domain's configuration, so the configuration must first be locked. In
the Change Center, click the Lock & Edit button.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 6/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

4. In the administration console under Domain Structure, expand Services (by clicking the + next to it). Then
click Data Sources.

On the right, notice that the Summary of JDBC Data Sources section appears.

5. Under the Data Sources table heading, click the New drop-down list. Then select Generic Data Source.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 7/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

6. On the first page of the Create a New JDBC Data Source wizard, enter the Name of the data source as
myNewDS .

Enter the JNDI Name of the data source as myNewDS .

Note: There is no requirement that the data source name and the JNDI name match. The JNDI name is the
one to make note of, because it is used by JDBC clients to access the data source.

Use the Database Type drop-down list to select Oracle .

Then click Next.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 8/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

7. On the second page of the wizard, use the Database Driver drop-down list to select
*Oracle's Driver (Thin) for Instance connections; Versions:9.0.1 and later .

Then click Next.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 9/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

8. On the next page of the wizard, keep all the default Transaction Options, and click Next.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 10/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

9. On the next page of the wizard, enter the Database Name. In this tutorial it is orcl Your database name may
be different.

Enter the Host Name of the server1 managed server. In this tutorial it is localhost . Use the host name
where your server1 server resides.

Leave the database Port at the default of 1521 . (Unless it is different for your database.)

Enter the Database User Name of DBTESTER . This is the user that was created by the SQL script.

Enter the database user's password twice, in the Password and Confirm Password fields. The password is
welcome1 .

Then click Next.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 11/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

10. On the next page of the wizard, click the Test Configuration button to check if a connection to the Database
can be made, based upon the information entered.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 12/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

If the connection test fails, use the Back button to review the entries made for the data source and correct any
errors. If there are no errors in the entries and the test still fails, make sure your database is running.

If the message "Connection test succeeded" is displayed, click Next.

11. On the last page of the wizard, the data source is targeted. Targeting a data source to a server means that the
server will manage that data source and it will be available as one of the resources of that server.

Select the check box next to server1.

Then click Finish.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 13/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

12. In the Change Center click the Activate Changes button.

The message "All changes have been activated. No restarts are necessary." is displayed.

13. In the Summary of JDBC Data Sources area, in the Data Sources table, the new data source, myNewDS, is
listed.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 14/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

14. To modify the configuration of the new data source, click its name, myNewDS, in the table.

15. Under the Settings for myNewDS, click the Connection Pool tab under the Configuration tab.

Scroll down to find the "capacity" fields


http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 15/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source
Scroll down to find the "capacity" fields.

For Initial Capacity enter 2 .

For Maximum Capacity enter 20 .

For Minimum Capacity enter 2 .

Then click Save.

In the Change Center click the Activate Changes button.

The messages "All changes have been activated. No restarts are necessary." and "Settings updated
successfully " are displayed
http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 16/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source
successfully. are displayed.

16. Under Domain Structure, expand Environment and then click Servers.

17. In the Servers table, click the server server1.

18. In the Settings for server1, under the Configuration tab and the General subtab, click the link View JNDI
Tree.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 17/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

The JNDI tree opens in a new browser window (or tab). Notice that myNewDS appears in the JNDI tree.

Note: Other entries in the JNDI tree of your server can be very different from what is shown here. It all
depends upon what resources your server has.

Testing the JDBC Data Source

To test the JDBC data source with a simple web application, perform the following steps:

1. Open a new Terminal window and navigate to the /server/bin directory under the WebLogic installation
directory. In this tutorial, that is:
/u01/wls1221/wlserver/server/bin

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 18/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

2. Then run the setWLSEnv.sh script as follows:

source setWLSEnv.sh

This will set the PATH and the CLASSPATH so the WLST deployment script can be executed.

3. Next navigate to the directory where the testds.war file resides. This file was part of the zip file extracted
earlier. In this tutorial, the zip file was extracted into the /u01/jdbc_obe/testds directory.

4. Before running the supplied WLST script, deploy_testds.py , you may need to edit it. The first line of the
script uses the connect() command. The first argument of that command is the domain administrator's
username, the second argument is that user's password, and the third argument is the host and port of the
administration server of the domain. Make sure the values for these arguments are correct for your domain
before running this script.
http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 19/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

Make any changes required to the script, and save the file.

5. Run the deploy_testds.py script to deploy the web application in the testds.war file and target it to the
server1 server. Do this by entering the following command:

java weblogic.WLST deploy_testds.py

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 20/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

You should see a message that the deploy operation has succeeded.

Note: You can ignore the warning about Context.close() . That warning is always displayed when running
a WLST script and is not an issue.

6. To verify the deployment was successful, go the the administration console, and under Domain Structure, click
Deployments. Then in the Deployments table, find TestDS with the "Active" State.

7. To use the deployed application, in another web browser, enter the host and port for the server1 managed
server, followed by /testds .

In this tutorial, the URL entered is:


http://localhost:7003/testds

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 21/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

8. When the application comes up, enter the following:

Data Source Name: myNewDS

Table Name: EMPLOYEE

Username: weblogic (use your domain administrator's username)

Password: welcome1 . (use your domain administrator's password)

9. Then click the Test Data Source button.

The rows in the EMPLOYEE table are displayed below the fields.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 22/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

The application uses the Data Source Name entered ( myNewDS ) as the JNDI name to look up the data
source from server1, retrieves a database connection from that data source, and executes the SQL to select
all the rows in the table entered in the Table Name field ( EMPLOYEE ).

If you want to test the data source again, try a different table in the Table Name field. The other two tables are
WLS_CATALOG_ITEMS and WLS_CLIENT_INFO .

Want to learn more?

In this tutorial, you learned how to:

Run a SQL script to set up a schema in an Oracle database


Start instances of WebLogic Server
Configure a JDBC data source by using the administration console
Test that data source by using a simple web application

Resources
http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 23/24
9/7/2018 Oracle WebLogic Server 12c: Configuring a JDBC Data Source

For documentation on Oracle WebLogic Server 12c, visit the Documentation Library
(http://docs.oracle.com/cd/E24329_01/index.htm).
For more information on creating JDBC data sources, see the Configuring and Managing JDBC Data Sources
(http://docs.oracle.com/cd/E24329_01/web.1211/e24367/toc.htm) document.
To learn more about Oracle WebLogic Server, refer to additional OBEs in the OLL
(http://www.oracle.com/goto/oll) website.

Credits

Lead Curriculum Developer: Bill Bell


About Oracle (http://www.oracle.com/corporate/index.html) Contact Us (http://www.oracle.com/us/corporate/contact/index.html)
Legal Notices (http://www.oracle.com/us/legal/index.html) Terms of Use (http://www.oracle.com/us/legal/terms/index.html)
Your Privacy Rights (http://www.oracle.com/us/legal/privacy/index.html)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/01-16-001-ConfigDataSource/configds.htm 24/24