+

Search Tips   |   Advanced Search

 

Example: Handling data access exception - ConnectionWaitTimeoutException (for J2EE Connector Architecture)

 

This code sample demonstrates how you specify the conditions under which WAS issues the ConnectionWaitTimeout exception for a JCA application.

In all cases in which the ConnectionWaitTimeout exception is caught, there is very little to do for recovery.

The following code fragment shows how to use this exception in J2EE Connector Architecture (JCA):

/**
 * This method does a simple Connection test. 
 */ public void testConnection()
   throws javax.naming.NamingException, javax.resource.ResourceException, 
       com.ibm.websphere.ce.j2c.ConnectionWaitTimeoutException {
   javax.resource.cci.ConnectionFactory factory = null;
   javax.resource.cci.Connection conn = null;
   javax.resource.cci.ConnectionMetaData metaData = null;
   try {
      // lookup the connection factory       if (verbose) System.out.println("Look up the connection factory..."); try { factory = 
   (javax.resource.cci.ConnectionFactory) (new InitialContext()).lookup("java:comp/env/eis/Sample");
  }
   catch (javax.naming.NamingException ne) {
      // Connection factory cannot be looked up.
      throw ne;   }
    // Get connection
      if (verbose) System.out.println("Get the connection...");
      conn = factory.getConnection();
      // Get ConnectionMetaData
      metaData = conn.getMetaData();
      // Print out the metadata Informatin.
      System.out.println("EISProductName is " + metaData.getEISProductName());   }
   catch (com.ibm.websphere.ce.j2c.ConnectionWaitTimeoutException cwtoe) {
      // Connection Wait Timeout
      throw cwtoe;   }
   catch (javax.resource.ResourceException re) {
      // Something wrong with connections.
      throw re;   }
   finally {
      if (conn != null) {
         try {
            conn.close();
         }
         catch (javax.resource.ResourceException re) {
         }
      }   }
}



 

Related concepts


Data sources
Connection pooling

 

Related Reference


Connection pool settings

 

Reference topic