Class AS400JDBCConnectionPool

  • All Implemented Interfaces:

    public class AS400JDBCConnectionPool
    extends ConnectionPool
    Represents a pool of JDBC connections that are available for use by a Java program.

    Note: AS400JDBCConnectionPool objects are threadsafe.

    The following example creates a connection pool with 10 connections.

      // Obtain an AS400JDBCConnectionPoolDataSource object from JNDI.
      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).
      // Get a handle to a database connection from the pool.
      Connection connection = pool.getConnection();
      ... Perform miscellenous queries/updates on the database.
      // Close the connection handle to return it to the pool.
      ... Application works with some more connections from the pool.
      // Close the pool to release all resources.
    See Also:
    Serialized Form
    • Constructor Detail

      • AS400JDBCConnectionPool

        public AS400JDBCConnectionPool()
        Constructs a default AS400JDBCConnectionPool object.
      • AS400JDBCConnectionPool

        public AS400JDBCConnectionPool(AS400JDBCConnectionPoolDataSource dataSource)
        Constructs an AS400JDBCConnectionPool object with the specified dataSource.
        dataSource - The AS400JDBCConnectionPoolDataSource object.
    • Method Detail

      • close

        public void close()
        Closes all the database connections in the pool.
        Specified by:
        close in class ConnectionPool
      • fill

        public void fill(int numberOfConnections)
                  throws ConnectionPoolException
        Fills the connection pool with the specified number of database connections.
        numberOfConnections - The number of connections to add to the pool.
        ConnectionPoolException - If a database error occurs creating a connection for the pool, or the maximum number of connections has been reached for the pool.
        ExtendedIllegalArgumentException - if the number of connections to fill the pool with is less than one.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Closes the connection pool if not explicitly closed by the caller.
        finalize in class ConnectionPool
        java.lang.Throwable - If an error occurs.
      • getActiveConnectionCount

        public int getActiveConnectionCount()
        Returns the number of active connections the pool has created.
        The number of active connections.
      • getAvailableConnectionCount

        public int getAvailableConnectionCount()
        Returns the number of available PooledConnections in the pool.
        The number of available PooledConnections.
      • getConnection

        public java.sql.Connection getConnection()
                                          throws ConnectionPoolException
        Returns a connection from the pool. Updates the pool cache.
        The connection.
        ConnectionPoolException - If a database error occurs getting the connection.
      • getDataSource

        public AS400JDBCConnectionPoolDataSource getDataSource()
        Returns the data source used to make connections.
        The AS400JDBCConnectionPoolDataSource object.
      • isClosed

        public boolean isClosed()
        Indicates whether the connection pool is closed.
        true if closed; false otherwise.
      • setDataSource

        public void setDataSource(AS400JDBCConnectionPoolDataSource dataSource)
                           throws java.beans.PropertyVetoException
        Sets the data source used to make connections.
        dataSource - The AS400JDBCConnectionPoolDataSource object.
        java.beans.PropertyVetoException - If a change is vetoed.