(For more resources on Oracle, see here.)
Setting the environment
In the following sections, we will learn how to set up the environment.
Installing required products
First, download and install the following required products; when installing the MySQL database, select the option to add the MySQL bin directory to the Windows system PATH environment variable:
- Oracle WebLogic Server 11g (http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html).
- Oracle Enterprise Pack for Eclipse All-In-One edition (http://www.oracle.com/technology/software/products/oepe/oepe_11113.html).
- MySQL 5.x database (http://www.oracle.com/us/products/mysql/index.html).
Creating a MySQL database table
Next, create a database table in the MySQL database as follows:
- Log in to the MySQL database with the following command:
>mysql
- Set database as test:
mysql>use test
- Run the following SQL script, which creates a Catalog table for the EJB 3 entity:
CREATE TABLE Catalog (id INT PRIMARY KEY NOT NULL,
journal VARCHAR(100), publisher VARCHAR(100), date VARCHAR(100),
title VARCHAR(100), author VARCHAR(100));
The output from the CREATE TABLE SQL script is shown in the following screenshot:

The table description may be listed with the desc command, as shown in the following illustration:

Configuring WebLogic Server with MySQL database
We shall be using a MySQL database for persistence. Therefore, we need to create a data source in WebLogic Server. Start the WebLogic Server and log in to the Administration Console.
Creating a data source
Select the base_domain | Services | JDBC | Data Sources. Click on New in the Data Sources table. Specify a data source name and a JNDI Name (jdbc/MySQLDS) for the data source. Select Database Type as MySQL and Database Driver as MySQL's Driver (Type 4): com.mysql.jdbc.Driver. Click on Next, as shown in the following screenshot:

(Move the mouse over the image to enlarge.)
In the Transaction Options window, select Supports Global Transactions and One-Phase Commit. Click on Next, as shown in the following screenshot:

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime
Specify the connection properties: Database Name as test, Host Name as localhost, Port as 3306, and Database User Name as root. Specify the Password used when installing MySQL and click on Next, as shown in the following screenshot:

In the Test Database Connection window, the Driver Class Name and connection URL are specified, normally filled from the information you entered in the previous screen. Click on Test Configuration to test the connection. Click on Finish, as shown in the following screenshot:

A data source gets added to the Data Sources table with its data source JNDI Name as jdbc/MySQLDS, as shown in the following screenshot:

Deploying the data source
Next, we deploy the data source to a target server. Click on the data source link in the Data Sources table and select the Targets tab. Select the AdminServer checkbox and click on Save, as shown in the following screenshot:

The target server changes get applied and saved:

Testing the data source
To test the data source, click on Test Data Source. If the data source tests without an error, a message indicating the same gets displayed as shown next:
