SourceForge.net Logo
Version: 0.27 - Last update: 2004-05-30 Home Page - SourceForge Project Page - Contact

Jodd
  Overview
  News
  Download
  License
  References

Development
  Using Jodd
  Javadoc
  JUnit report

Community
  Contribute
  Report a bug

More reading
  Milestone 0.30



Top 25%

BSD
 

ConnectionPool

There is nothing much to say about database connection pools - they should be used. Therefore ConnectionPool represent a generic database connection pool interface. The same package also contains a few implementations of this interface:
  • CoreConnectionPool - nice database-independent connection pool.
  • OracleConnectionPool - Oracle has its own pool (OracleConnectionCacheImpl). This pool serves as ConnectionPool interface adapter for Oracles pool.
  • ContextConnectionPool - just an adapter for pools that are set via InitialContext, as in Tomcat4.
  • NoConnectionPool - no pool at all, connections are not cached.

Each of these pool implementations has its own way of initialization. Therefore, once a ConnectionPool object is instanced, it has to be populated with the required data. After that, init() method of pool object can be called to initialize the pool. When pool is not needed any more it should be closed with close() method.

Here is an example of standard initialization of a connection pool.

ConnectionPool usage
 
ConnectionPool pool = new CoreConnectionPool();
((CoreConnectionPool)pool).setDriver(...);		// pool specific settings
((CoreConnectionPool)pool).setUser(...);
((CoreConnectionPool)pool).setPassword(...);

try {
	pool.init();
} catch (SqlException sex) {
	...			// do something with an exception
}
		
				
pool.getConnection();		// get connection from pool
...
pool.freeConnection();		// return connection back to pool


pool.close();

The behaviour of the pool depends on specific implementation.


http://jodd.sourceforge.net
najgor at users.sourceforge.net