Using a JDBC 2.0 Optional Package Connection Pool
Connection pools exist in many forms. You find them in books, articles, and on the Web. Yet prior to JDBC 2.0, there was no standard defined for how a Java application would interact with a connection pool. The JDBC 2.0 Optional Package (formerly known as a Standard Extension), now part of JDBC 3.0 and included in the Java SDK 1.4, changed this by introducing a set of interfaces that connection pools should implement:
-
javax.sql.DataSource A
DataSourcerepresents a database. This is the interface the application always uses to get aConnection. The class that implements the interface can provide connection-pooling capabilities or hand out regular, unpooledConnectionobjects; the application code is identical for both cases, as described later.-
javax.sql.ConnectionPoolDataSource A
DataSourceimplementation that provides pooling capabilities uses a class that implements theConnectionPoolDataSourceinterface. AConnectionPoolDataSourceis a factory forPooledConnectionobjects. The application code never calls methods in this interface directly.-
javax.sql.PooledConnection The objects a
DataSourcewith pooling capabilities keeps in its pool implement thePooledConnectioninterface. When the application asks theDataSourcefor aConnection, it locates an availablePooledConnectionobject or gets a new one from itsConnectionPoolDataSourceif the pool is empty.The
PooledConnectionprovides agetConnection( )method that returns aConnection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access