• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

CONNECTION POOL in WAS 3.5

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body tell me how to create connection pools in WAS 3.5 and use them in EJB, JSP etc
Thanx :-)
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic