# JdbcConnectionPool

A simple standalone JDBC connection pool. It is based on the MiniConnectionPoolManager written by Christian d'Heureuse (Java 1.5) . It is used as follows:

     import java.sql.*;
     import org.h2.jdbcx.JdbcConnectionPool;
     public class Test {
         public static void main(String... args) throws Exception {
             JdbcConnectionPool cp = JdbcConnectionPool.create(
                 "jdbc:h2:~/test", "sa", "sa");
             for (String sql : args) {
                 Connection conn = cp.getConnection();
                 conn.createStatement().execute(sql);
                 conn.close();
             }
             cp.dispose();
         }
     }

Methods
static JdbcConnectionPool | create(ConnectionPoolDataSource dataSource) Constructs a new connection pool.
static JdbcConnectionPool | create(ConnectionPoolDataSource dataSource) Constructs a new connection pool. Parameters: dataSource - the data source to create connections Returns: the connection pool
static JdbcConnectionPool | create(String url, String user, String password) Constructs a new connection pool for H2 databases.
static JdbcConnectionPool | create(String url, String user, String password) Constructs a new connection pool for H2 databases. Parameters: url - the database URL of the H2 connection user - the user name password - the password Returns: the connection pool
void | dispose() Closes all unused pooled connections.
void | dispose() Closes all unused pooled connections. Exceptions while closing are written to the log stream (if set).
int | getActiveConnections() Returns the number of active (open) connections of this pool.
int | getActiveConnections() Returns the number of active (open) connections of this pool. This is the number of `Connection` objects that have been issued by getConnection() for which `Connection.close()` has not yet been called. Returns: the number of active connections.
Connection | getConnection() Retrieves a connection from the connection pool.

Connection

getConnection() throws SQLException
Retrieves a connection from the connection pool. If `maxConnections` connections are already in use, the method waits until a connection becomes available or `timeout` seconds elapsed. When the application is finished using the connection, it must close it in order to return it to the pool. If no connection becomes available within the given timeout, an exception with SQL state 08001 and vendor code 8001 is thrown.
Returns:
a new Connection object.
Throws:
SQLException - when a new connection could not be established, or a timeout occurred

int | getLoginTimeout() Gets the maximum time in seconds to wait for a free connection.
int | getLoginTimeout() Gets the maximum time in seconds to wait for a free connection. Returns: the timeout in seconds
int | getMaxConnections() Gets the maximum number of connections to use.
int | getMaxConnections() Gets the maximum number of connections to use. Returns: the max the maximum number of connections
Logger | getParentLogger() [Not supported]
Logger | getParentLogger() [Not supported]
boolean | isWrapperFor(Class iface) [Not supported] Checks if unwrap can return an object of this class.
boolean | isWrapperFor(Class iface) throws SQLException [Not supported] Checks if unwrap can return an object of this class. Parameters: iface - the class
void | setLoginTimeout(int seconds) Sets the maximum time in seconds to wait for a free connection.
void | setLoginTimeout(int seconds) Sets the maximum time in seconds to wait for a free connection. The default timeout is 30 seconds. Calling this method with the value 0 will set the timeout to the default value. Parameters: seconds - the timeout, 0 meaning the default
void | setMaxConnections(int max) Sets the maximum number of connections to use from now on.
void | setMaxConnections(int max) Sets the maximum number of connections to use from now on. The default value is 10 connections. Parameters: max - the maximum number of connections
T | unwrap(Class iface) [Not supported] Return an object of this class if possible.
T | unwrap(Class iface) throws SQLException [Not supported] Return an object of this class if possible. Parameters: iface - the class