This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Websphere and the fly likes Connection Pool in WebSphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Connection Pool in WebSphere" Watch "Connection Pool in WebSphere" New topic
Author

Connection Pool in WebSphere

chandubcs
Ranch Hand

Joined: Jun 03, 2001
Posts: 47
Hi all,
I have WSAD 5.1 and Oracle 8.1.7. Presently I am hardcoding the DB URL, username, password using JDBC thin driver. I want to prepare a connection pool for this Oracle connection in WSAD and use that connection pool name from my applications. How can I setup or create a connection pool in WSAD for Oracle database.
Thanks in advance.
maneesh subherwal
Ranch Hand

Joined: Aug 26, 2002
Posts: 42
This is a slightly lengthy description, so please bear with me...
1. Go to the 'Server Perspective' in WSAD.
2. If you have a server set up already, u will need to click on the server to set up the configuration.
3. Go to the Datasource Tab
4. Under 'JDBC Provider List', select the Add button.
5. Select Oracle and the Oracle Thin Driver.
6. Set the implementation class name to oracle.jdbc.pool.OracleConnectionPoolDataSource and specify a name (oracleDS) for this datasource.
7. Under DataSource, set a name (ORADS) and JNDI name (jdbc/ORADS). leave everything else as is.
8. Under Resource properties (with your ORADS Datasource selected), Add name as 'URL' and value as 'jdbc racle:thin:@serverName ort b'.
9. Save this and restart your server.
10. Use the following code to retrieve the datasource:
try
{

Hashtable parms = new Hashtable();
parms.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
parms.put(Context.PROVIDER_URL, "iiop:///");
InitialContext ctx = new InitialContext(parms);
DataSource ds = (DataSource)ctx.lookup("jdbc/ORADS"); // if that is what you named it...

}
catch(NamingException e)
{
System.out.println(e);
}

11. To Use the datasource,
ds.getConnection(userId, password);
I hope this helps...
Thanks,
Maneesh


Sun Certified Java Programmer 2 (1.4)<br />Sun Certified Web Component Developer
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
One point,
Please start using default InitialContext constructor. Now in version 5, there is local namespace for each server proces..
chandubcs
Ranch Hand

Joined: Jun 03, 2001
Posts: 47
Hi again,
I tried that code, its good to know that it worked properly and I got connection. Thanks.
I have created a data source name as "DSN1", But I am getting some messages at server output, like:
Resource reference jdbc/DSN1 could not be located, so default values of the following are used: [Resource-ref settings]
res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
res-resolution-control: 999 (undefined)
[Other attributes]
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)
[11/19/03 13:40:02:793 EST] 40000c3d ConnectionFac I J2CA0107I: Component-managed authentication alias not specified for connection factory or datasource DSN1.
[11/19/03 13:40:05:306 EST] 40000c3d WSRdbDataSour u Database version is
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production
[11/19/03 13:40:05:306 EST] 40000c3d WSRdbDataSour u JDBC Driver version is
8.1.7.1.0
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
Yes.. it will happen as you dont have a reference in your web deployment descriptor. You are trying to refer to this datasource from the Web project.. isnt it?
chandubcs
Ranch Hand

Joined: Jun 03, 2001
Posts: 47
Yes, I am calling it from a Web Project (from JSP). What is the best way to change the code to avoid that warning message.
Thanks,
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
Go to Web Deployment Descriptor, click on references tab, click on Resources tab
Click on Add button
(New ResourceRef) - replace this with the jndi name you gave in ur program. For example if you gave java:comp/env/jdbc/testds, type jdbc/typeds.
Type = javax.sql.DataSource (Make sure you havent selected javax.activation.DataSource:-)
Under Websphere Bindings
jndiname - name you gave while created your datasource.
Save
Restart your server.
Good luck
-Mahesh
 
jQuery in Action, 2nd edition
 
subject: Connection Pool in WebSphere