com.ibm.as400.access

Class AS400JDBCPooledConnection

  • All Implemented Interfaces:
    PooledConnection
    Direct Known Subclasses:
    AS400JDBCXAConnection


    public class AS400JDBCPooledConnection
    extends Object
    implements PooledConnection
    The AS400JDBCPooledConnection class represents a connection object that provides hooks for connection pool management. This object is returned by the AS400JDBCConnectionPoolDataSource.getPooledConnection() method. The following example creates an AS400JDBCPooledConnection object that can be used to cache JDBC connections.
    // Create a data source for making the connection. AS400JDBCConnectionPoolDataSource dataSource = new AS400JDBCConnectionPoolDataSource("myAS400"); datasource.setUser("Mickey Mouse"); datasource.setPassword("IAMNORAT"); // Get a PooledConnection and get the connection handle to the database. AS400JDBCPooledConnection pooledConnection = datasource.getPooledConnection(); Connection connection = pooledConnection.getConnection(); ... work with the connection handle. // Close the connection handle to make available for reuse (physical connection not closed). connection.close(); // Reuse the connection somewhere else. Connection reusedConnection = pooledConnection.getConnection(); ... work with the connection handle. reusedConnection.close(); // Close the physical connection. pooledConnection.close();

    AS400JDBCPooledConnection objects generate the following events:

    • javax.sql.ConnectionEvent - The events fired are:
      • connectionClosed
      • connectionErrorOccurred

    • Method Detail

      • closeAll

        public void closeAll()
                      throws SQLException
        Closes all the Statement objects that have been opened by this PooledConnection object. This method is not supported.
        Throws:
        SQLException - Always thrown because this method is not supported.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getConnection

        public Connection getConnection()
                                 throws SQLException
        Returns the connection handle to the database. Only one connection handle can be open at a time for any given AS400JDBCPooledConnection object.
        Specified by:
        getConnection in interface PooledConnection
        Returns:
        The connection handle.
        Throws:
        SQLException - If a database error occurs or if this PooledConnection is already in use.
      • getInactivityTime

        public long getInactivityTime()
        Returns the elapsed time the connection has been idle waiting in the pool.
        Returns:
        The idle time (milliseconds).
      • getInUseTime

        public long getInUseTime()
        Returns the elapsed time the connection has been in use.
        Returns:
        The elapsed time (milliseconds).
      • getLifeSpan

        public long getLifeSpan()
        Returns the elapsed time the pooled connection has been alive.
        Returns:
        The elapsed time (milliseconds).
      • getUseCount

        public int getUseCount()
        Returns the number of times the pooled connection has been used.
        Returns:
        The number of times used.
      • isInUse

        public boolean isInUse()
        Indicates if the pooled connection is in use.
        Returns:
        true if the pooled connection is in use; false otherwise.