Java Reference
In-Depth Information
ConnectionPool pool = new ConnectionPool();
// Set the JDBC Driver
// Set the URL to the Datasource
pool.setURL(“jdbc:odbc:Movie Catalog”);
// Set the initial size of the Connection Pool
// Set the Username
// Set the Password
// Initialize the pool
The init() method first creates an instance of the ConnectionPool . It then sets the accessors
appropriately. It sets the driver to the JDBC-ODBC Bridge, the data source URL to the Movie
Catalog, and the initial number of connections to 4. The next two accessors (username and
password) are set to empty strings. This is because the Microsoft Access database that we have
created has no login or password.
The last executable line of the init() method initializes the ConnectionPool . This is where
the ConnectionPool connections begin their life. An excerpt of the ConnectionPool's
initializePool() method is listed as follows:
// Load the Driver class file
// Create Connections based on the size member
for ( int x = 0; x < size; x++ ) {
System.err.println(“Opening JDBC Connection “ + x);
Connection con = createConnection();
if ( con != null ) {
// Create a PooledConnection to encapsulate the
// real JDBC Connection
PooledConnection pcon = new PooledConnection(con);
// Add the Connection the pool.
Search WWH ::

Custom Search