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:
 // init
 import org.h2.jdbcx.*;
 ...
 JdbcDataSource ds = new JdbcDataSource();
 ds.setURL("jdbc:h2:~/test");
 ds.setUser("sa");
 ds.setPassword("sa");
 JdbcConnectionPool cp = JdbcConnectionPool.create(ds);
 // use
 Connection conn = cp.getConnection();
 ...
 conn.close();
 // dispose
 cp.dispose();


Methods
static JdbcConnectionPool create(ConnectionPoolDataSource dataSource)
Constructs a new connection pool.
void dispose()
Closes all unused pooled connections.
int getActiveConnections()
Returns the number of active (open) connections of this pool.
Connection getConnection()
Retrieves a connection from the connection pool.
int getLoginTimeout()
Gets the maximum time in seconds to wait for a free connection.
int getMaxConnections()
Gets the maximum number of connections to use.
void setLoginTimeout(int seconds)
Sets the maximum time in seconds to wait for a free connection.
void setMaxConnections(int max)
Sets the maximum number of connections to use from now on.

static JdbcConnectionPool create(ConnectionPoolDataSource dataSource)

Constructs a new connection pool.

Parameters:
dataSource - the data source to create connections
Returns:
the connection pool

void dispose() throws SQLException

Closes all unused pooled connections.

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() 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.

Returns:
the timeout in seconds

int getMaxConnections()

Gets the maximum number of connections to use.

Returns:
the max the maximum number of connections

void setLoginTimeout(int seconds)

Sets the maximum time in seconds to wait for a free connection. The default timeout is 60 seconds.

Parameters:
seconds - the maximum timeout

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