Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ConnectionPoolDataSource

 
karim qazi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain to me how to use the ConnectionPoolDataSource vs. DataSource.
I know how to get a connection using the DataSource interface how can you get a ConnectionPoolDataSource instead?
 
Robert Brunner
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karim qazi:
Can anyone explain to me how to use the ConnectionPoolDataSource vs. DataSource.
I know how to get a connection using the DataSource interface how can you get a ConnectionPoolDataSource instead?


Easy, rather than creating an object that implements the DataSource interface, you implement an object that implements the ConnectionPoolDataSource.
You then get a PooledConnection object via getPooledConnection(), and then you get a connection from this PooledConnection via getConnection(). Everything else is the same. So essentially, you only have one changed step, and one additional step to take advantage of connection pooling.
<pre>
ConnectionPoolDataSource ds = new ConnectionPoolDataSource() ;
// Set datasource properties
PooledConnection pcon = ds.getPooledConnection() ;
Connection con = pcon.getConnection() ;
<pre>
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One Correction:
ConnectionPoolDataSource is a Interface.
So You cann't use ConnectionPoolDataSource ds= new ConnectionPoolDataSource();

Regards,
Raman
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic