Recipe 21.4 Creating a DataSource on WebLogic
Problem
You want to
create a javax.sql.DataSource
on BEA WebLogic for use in your servlets.
Solution
Use the WebLogic console to configure a new connection pool, then
configure a new DataSource associated with that
pool.
Discussion
Configuring a WebLogic DataSource involves the
following
steps:
Login to the WebLogic console, which allows you to manage
the WebLogic server from a browser. The URL for the console is
typically http://<localhost:7001>/console
(substitute your host name for
"localhost" and the port number
that matches your own WebLogic configuration). Click on Your-domain-name
Services JDBC Connnection Pools on the menu
tree in the console's lefthand column. Then click on
"Configure a new JDBC Connection Pool . . .
". In the resulting window, enter a name for the connection pool, the
JDBC URL (e.g.,
jdbc:oracle:thin:@192.168.0.2:1521:ORCL), the
Driver class name (e.g.,
oracle.jdbc.driver.OracleDriver), as well as the
username and password in the
"Properties" text field. Figure 21-2 shows a configured connection pool named
"OraclePool." Remember this
name—you'll need it to configure a
DataSource further along in the process.
Click on the "Create" button in
this window to create the connection pool, then choose the
"Targets" tab. The resulting screen
allows you to choose a server to which the connection pool will
apply. After you have chosen the server, click on the
"Apply" button in the Targets
screen. The name of the new pool should appear in the lefthand menu
frame. Click on Your-domain-name
Services JDBC Data Sources and click on the URL
"Configure a New JDBC Data Source . . .
". Figure 21-3 shows a
DataSource configuration window that includes the
DataSource name
("oracle-8i-athletes") under which
WebLogic will bind the DataSource as a JNDI
object. The window also has a text field where you must enter the
name of the connection pool that you just configured:
"OraclePool." Click the
"Create" button to create the new
DataSource. Figure 21-3 shows the JDBC Data Sources
window. Take the same steps as in step 4 with the
"Targets" screen to apply this
DataSource to the appropriate server. Painless,
right?
Figure 21-4 shows the WebLogic
JNDI
tree where the DataSource that you have just
created is bound.
See Also
The JDBC specification: http://java.sun.com/products/jdbc/download.html;
Chapter 2 on deploying servlets and JSPs on
WebLogic; Recipe 21.2 and Recipe 21.3 on using a
DataSource on Tomcat; Recipe 21.5 and Recipe 21.6 on using DataSources with
servlets and JSPs on WebLogic.
![](FILES/pixel.gif) |