dbutils
Class ConnectionPool
java.lang.Object
|
+--dbutils.ConnectionPool
- public class ConnectionPool
- extends java.lang.Object
The Connection Pool class creates a hashtable that represents a pool of
up to ten connections and connsists of two main functions.
The getConnection function returns the first available connection in the pool.
The returnConnection function returns a used connection back to the hashtable
for reuse
Constructor Summary |
ConnectionPool()
Constructor class of the Connection pool that creates the maximum number
of connections and stores the connections in a hashtable. |
Method Summary |
java.sql.Connection |
getConnection()
This function returns the first available connection in the hashtable of connections
marked with a Boolean false and sets the connection to used with a Boolean true. |
static ConnectionPool |
getInstance()
Implements a Singleton pattern of the ConnectionPool. |
void |
returnConnection(java.sql.Connection returned)
This function sets the used connection in the connection pool to a Boolean
false and declares the connection free for use. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConnectionPool
public ConnectionPool()
throws JDBCException
- Constructor class of the Connection pool that creates the maximum number
of connections and stores the connections in a hashtable. The connections
are either in use with a Boolean true or they are free to use with a Boolean
false.
- Throws:
JDBCException
- an error has occured when connecting to the database or a failure to load database drivers
getInstance
public static ConnectionPool getInstance()
throws JDBCException
- Implements a Singleton pattern of the ConnectionPool. Creates an instance if
one does not exist. Returns ConnectionPool instance.
- Returns:
- ConnectionPool (instance)
- Throws:
JDBCException
- an error has occured in connecting to the database or with loading the oracle drivers
getConnection
public java.sql.Connection getConnection()
throws JDBCException
- This function returns the first available connection in the hashtable of connections
marked with a Boolean false and sets the connection to used with a Boolean true.
- Returns:
- Connection to the database
- Throws:
JDBCException
- catches a SQLException if connection fails in the hashtable of connections and creates a new connection
returnConnection
public void returnConnection(java.sql.Connection returned)
- This function sets the used connection in the connection pool to a Boolean
false and declares the connection free for use.
- Parameters:
returned
- connection to be returned to the database