hi I have created connection pooling for my Java Stand alone program.
Okay to be more clear ..
private static ComboPooledDataSource = pooledDataSource;
public static void createDataSource(String dbName)
{
if(dbName.equals("DB_ONE"))
{
pooledDataSource = new ComboPooledDataSource();
// Here passing parameters will be different for DB_ONE
pooledDataSource.setDriverClass(dbDriver);
pooledDataSource.setJdbcUrl(dbUrl);
pooledDataSource.setUser(userID);
pooledDataSource.setPassword(password);
pooledDataSource.setMinPoolSize(Integer.parseInt(minCon));
pooledDataSource.setMaxPoolSize(Integer.parseInt(maxCon));
pooledDataSource.setMaxIdleTime(Integer.parseInt(maxIdleTime));
pooledDataSource.setInitialPoolSize(Integer.parseInt(intialPoolSize));
pooledDataSource.setPreferredTestQuery(testQuery);
}
if(dbName.equals("DB_TWO"))
{
pooledDataSource = new ComboPooledDataSource();
// Here passing parameters will be different for DB_TWO
pooledDataSource.setDriverClass(dbDriver);
pooledDataSource.setJdbcUrl(dbUrl);
pooledDataSource.setUser(userID);
pooledDataSource.setPassword(password);
pooledDataSource.setMinPoolSize(Integer.parseInt(minCon));
pooledDataSource.setMaxPoolSize(Integer.parseInt(maxCon));
pooledDataSource.setMaxIdleTime(Integer.parseInt(maxIdleTime));
pooledDataSource.setInitialPoolSize(Integer.parseInt(intialPoolSize));
pooledDataSource.setPreferredTestQuery(testQuery);
}
}
public Connection getConnection(String dbName)
{
createDataSource(dbName);
return pooledDataSource.getConnection();
}
In my DAO class whenever I call this method getConnection(dbName)
Swithcing between Two differnt databases frequesntly.. for every connection calling that particualr database pool is getting created again.
I dont want to create duplicate pools ...
How to avoid creating new connection pool
?
any help Thanks in adavance.
Maybe you can think about something like this :
With this solution, you create your data sources only when you need (but keep it alive after its creation) and you can access connection from the data source you want without creating new pool.