Order the Book

coreservlets
Class ConnectionPool

java.lang.Object
  |
  +--coreservlets.ConnectionPool

public class ConnectionPool
extends Object
implements Runnable

A class for preallocating, recycling, and managing JDBC connections.

Taken from Core Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/. © 2000 Marty Hall; may be freely used or adapted.


Constructor Summary
ConnectionPool(String driver, String url, String username, String password, int initialConnections, int maxConnections, boolean waitIfBusy)
           
 
Method Summary
 void closeAllConnections()
          Close all the connections.
 void free(Connection connection)
           
 Connection getConnection()
           
 void run()
           
 String toString()
           
 int totalConnections()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(String driver,
                      String url,
                      String username,
                      String password,
                      int initialConnections,
                      int maxConnections,
                      boolean waitIfBusy)
               throws SQLException
Method Detail

getConnection

public Connection getConnection()
                         throws SQLException

run

public void run()
Specified by:
run in interface Runnable

free

public void free(Connection connection)

totalConnections

public int totalConnections()

closeAllConnections

public void closeAllConnections()
Close all the connections. Use with caution: be sure no connections are in use before calling. Note that you are not required to call this when done with a ConnectionPool, since connections are guaranteed to be closed when garbage collected. But this method gives more control regarding when the connections are closed.

toString

public String toString()
Overrides:
toString in class Object

Order the Book

Order
CSAJSP @ amazon.com

Return to Top-Level Source Code Archive