Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It’s common to inherit a bit of code written with neither DataSources nor connection pooling of any sort in mind at all. For a variety of reasons, it may not be feasible to change your existing program logic (beyond editing the JDBC connection strings). Fortunately, DBCP supports the notion of a PoolingDriver—an implementation of a JDBC driver that implements a connection pool behind the scenes. As long as your application code opens and closes connections properly, you can add connection pooling at any time.
Listing 6-4 shows how a bit of legacy code can be adapted to support a connection pool. As you can see, you will still need to add a bit of code to initialize the connection pool (as shown in the registerPoolingDriver() method) to your legacy application’s initialization process.