File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes CONNECTION POOL in WAS 3.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "CONNECTION POOL in WAS 3.5" Watch "CONNECTION POOL in WAS 3.5" New topic
Author

CONNECTION POOL in WAS 3.5

mou haj
Ranch Hand

Joined: Sep 12, 2001
Posts: 81
Can any body tell me how to create connection pools in WAS 3.5 and use them in EJB, JSP etc
Thanx :-)
Peter Garduno
Greenhorn

Joined: Feb 15, 2002
Posts: 2
Weel, I hope this helps you
To create a datasource on demand in an application, the application must do the following:


1. Create a Properties object with datasource properties.

2. Obtain a datasource from the factory.

3. Bind the datasource into JNDI.


import com.ibm.websphere.advanced.cm.factory.DataSourceFactory;


try {

//Create a properties file for the DataSource java.util.Properties prop = new java.util.Properties();

prop.put(DataSourceFactory.NAME,"SampleDB");

prop.put(DataSourceFactory.DATASOURCE_CLASS_NAME,
"COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource");

prop.put(DataSourceFactory.DESCRIPTION,"My sample
datasource");

prop.put("databaseName", "sample");


//Obtain a DataSource from the factory
DataSource ds = DataSourceFactory.getDataSource(prop);

//Bind the DataSource into JNDI
DataSourceFactory.bindDataSource(ds);

} catch (ClassNotFoundException cnfe){

//check the class path for all necessary classes


} catch (CMFactoryException cmfe){

//Example of exception: incorrect

properties

} catch (NamingException ne) {

//Example of exception:

//datasource by this name may already exist

}

I am working with WebSphere 4.0 and I am also using the pool, we could stay in contact to help each other.
ravindran shanmugam
Greenhorn

Joined: Aug 30, 2001
Posts: 15
How do we actually get the database connection after that ?

I'm using the following class for getting connection ,

class DBConnect {
static DataSource ds = null;
static {
try {
Hashtable parms = new Hashtable();
parms.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
Context ctx = new InitialContext(parms);
ds = (DataSource) ctx.lookup("jdbc/jndi");
}catch(Exception e) {
}
}
public Connection getDBConnection(){
Connection conn = null;
try {
conn = ds.getConnection("USER","PASSWD");
}catch(Exception e) {
}
}
}
and calling getconnection whenever I need a connection. Will this not maintain a connection pool. In the help page Websphere states that getting connection thorugh DataSource will automatically maintain a connection Pool.
please include me in your loop
Regards
Ravindran.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CONNECTION POOL in WAS 3.5