JavaXT

ConnectionPool Class

A lightweight standalone JDBC connection pool manager.

Constructors

public ConnectionPool( javaxt.sql.Database database, int maxConnections )
public ConnectionPool( javaxt.sql.Database database, int maxConnections, int timeout )
public ConnectionPool( javax.sql.ConnectionPoolDataSource dataSource, int maxConnections )
public ConnectionPool( javax.sql.ConnectionPoolDataSource dataSource, int maxConnections, int timeout )

Methods

close( ) returns void
Closes all unused pooled connections.
getActiveConnections( ) returns int
Returns the number of active (open) connections of this pool.

This is the number of Connection objects that have been issued by {@link #getConnection()}, for which Connection.close() has not yet been called.

getConnection( ) returns javaxt.sql.Connection
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.

getConnectionPoolDataSource( ) returns javax.sql.ConnectionPoolDataSource
getInactiveConnections( ) returns int
Returns the number of inactive (unused) connections in this pool.

This is the number of internally kept recycled connections, for which Connection.close() has been called and which have not yet been reused.

getMaxConnections( ) returns int
getTimeout( ) returns int
getValidConnection( ) returns javaxt.sql.Connection
Retrieves a connection from the connection pool and ensures that it is valid by calling {@link Connection#isValid(int)}.

If a connection is not valid, the method tries to get another connection until one is valid (or a timeout occurs).

Pooled connections may become invalid when e.g. the database server is restarted.

This method is slower than {@link #getConnection()} because the JDBC driver has to send an extra command to the database server to test the connection.

This method requires Java 1.6 or newer.