|
useful tools from Apache Jakata Commons - dbcp |
|
|
|
|
Written by Sleepy Egg
|
|
Monday, 27 June 2005 |
|
dbcp is an implementation of Java connection pooling. This uses the common-pooling API. You can implement a generice Database class to wrap both JDBC connection pooling using dbcp and datasource looking using JNDI. Once this is done, you don't have to care about how it gets the connection from.
example:
for connection pooling using dbcp :
http://cvs.apache.org/viewcvs.cgi/jakarta-commons/dbcp/doc/BasicDataSourceExample.java?rev=1.2&view=markup
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUsername("scott");
ds.setPassword("tiger");
ds.setUrl(connectURI);
return ds;
BasiceDataSource is a subclass of DataSource.
So doesn't matter if it is from JNDI lookup or from dbcp, cache it. The only method you need to implement is getConnection(), which get connection from the datasource.
|