Before you begin, make sure that you have Oracle installed and a database is created. In this document we will use a database called MALL.
Create a WAS V5 Server
If you don’t already have a WebSphere V5 server created, do so following these steps. Switch to the Serverperspective. Right click in the Server Configuration view and select New->Server and Server Configuration.
Name the server WASV5. Make sure that the Server type is set to WebSphere version 5.0->Test Environment. Click on Finish.
Add the Database User
In WSAD5, the default user ID and password to be used by a DataSource are first entered as a JAAS authentication entry.
In the Server Configuration view, double click on WASV5 to open the configuration editor. Click on the Security tab. Next to the JAAS Authentication Entries list click on Add and add the user.
Add the JDBC Driver
Still in the server configuration GUI click on the DataSource tab. You can add the DataSource at the server level or at the node level. We will add it at the server level. Make sure that the Server Settings is expanded. Next to the JDBC providers list click on Add.
Select the following options:
Database type: Oracle
JDBC provider type: Oracle JDBC Thin Driver or the XA version of it if you need two phase commit transaction.
Click on Next.
Set the name to Oracle Thin Driver.
Notice that the location of the driver’s class is automatically set to ${ORACLE_JDBC_DRIVER_PATH}/classes12.zip. Here, ORACLE_JDBC_DRIVER_PATH is a node level variable. We need to make sure that the variable is pointing to the correct directory where Oracle’s JDBC driver is installed. In our case, we had installed Oracle in c:oracle. This had installed the JDBC driver class in C:/oracle/ora81/jdbc/lib/classes12.zip.
In the server configuration GUI click on the Variables tab. Under the Node settings select ORACLE_JDBC_DRIVER_PATH from the Defined variables list. Click on Edit and set the value to C:/oracle/ora81/jdbc/lib.
Add the DataSource
Click on the DataSource tab again. Select the Oracle Thin Driver you had created in the previous step. Click on Addnext to the Data source defined in the JDBC provider selected above list.
Select the following options:
Select the type of JDBC Driver: Oracle JDBC Thin Driver.
Select the data source type: Unless you will be testing your application with WAS V4, select Version 5.0. You can not use a V4 DataSource from a J2EE 1.3 EJB module running in WebSphere V5.
Click on Next.
Enter these key attributes in this screen:
Name: My Oracle DataSource
JNDI Name: jdbc/MyDataSource
DataSource helper class name: com.ibm.websphere.rsadapter.OracleDataStoreHelper. Should be selected by default. The helper class is needed if you wish to access IBM extensions to JDBC. For more details search in WSAD help for “WSDataSource interface”.
Component-managed authentication alias: Set this if you wish to lookup the DataSource using its global JNDI name or using the java:comp/env/ name space and have set the authentication type of the resource reference to Application. Select the JAAS entry you had created. That is, Database user.
Container-managed authentication alias: Set this if you intend to lookup the DataSource using the java:comp/env/ name space and have set the authentication type of the resource reference to Container. Select the JAAS entry you had created. That is, Database user.
Use this data source in container managed persistence (CMP): Check on if you intend to use the DataSource from CMP EJBs.
Click on Next.
You need to set these properties:
databaseName: MALL in our case.
URL: jdbc:oracle:thin:@noble.webagesolutions.com:1521:MALL. In my case the server host name is noble.webagesolutions.com. The listener port number is 1521 (usually the default in most Oracle installations).
Click on Finish.
You have finished adding the DataSource. Save the server settings by clicking Control+S. Close the server configuration GUI.
Testing the DataSource
There is no out of the box way to test the DataSource. You can create a simple Servlet and add the following code:
public void doGet(HttpServletRequest req, HttpServletResponse resp) javax.sql.DataSource ds = null; java.sql.Connection con = null; java.io.PrintWriter out = resp.getWriter(); resp.setContentType("text/html"); try { out.println("Looking up DataSource<br>"); javax.naming.InitialContext ctx = new javax.naming.InitialContext(); ds = (javax.sql.DataSource) ctx.lookup("jdbc/MyDataSource"); out.println("Getting connection<br>"); con = ds.getConnection(); con.close(); } catch (Exception e) { e.printStackTrace(out); } out.println("Done<br>"); }