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.
