The AS400JDBCConnectionPool class represents a pool of AS400JDBCConnection objects that are available for use by a Java™ program as part of IBM® Toolbox for Java support for the JDBC 2.0 Optional Package API.
You can use an AS400JDBCConnectionPoolDataSource to specify properties for the connections that are created in the pool, as in the following example.
You cannot change the connection pool data source after you have requested a connection and the pool is in use. To reset the connection pool data source, first call close() on the pool.
Return connections to an AS400JDBCConnectionPool by using close() on the AS400JDBCConnection object.
Set properties on the pool by using methods inherited from ConnectionPool. Some of the properties that you can set include:
You can also register AS400JDBCConnectionPoolDataSource objects by using a Java Naming and Directory Interface(TM) (JNDI) service provider. For more information on JNDI service providers, see IBM Toolbox for Java reference links.
The following example gets a connection pool data source from JNDI and uses it to create a connection pool with 10 connections:
// Obtain an AS400JDBCConnectionPoolDataSource object from JNDI // (assumes JNDI environment is set). Context context = new InitialContext(environment); AS400JDBCConnectionPoolDataSource datasource = (AS400JDBCConnectionPoolDataSource)context.lookup("jdbc/myDatabase"); // Create an AS400JDBCConnectionPool object. AS400JDBCConnectionPool pool = new AS400JDBCConnectionPool(datasource); // Adds 10 connections to the pool that can be used by the // application (creates the physical database connections based on // the data source). pool.fill(10); // Get a handle to a database connection from the pool. Connection connection = pool.getConnection(); ... Perform miscellaneous queries/updates on the database. // Close the connection handle to return it to the pool. connection.close(); ... Application works with some more connections from the pool. // Close the pool to release all resources. pool.close();