Example: Handling data access exception - error mapping in DataStoreHelper

Error mapping is necessary because various database vendors can provide differing SQL errors and codes that might mean the same things. For example, the StaleConnectionException has different codes in different databases. The DB2 SQLCODEs of 1015, 1034, 1036 and so on, indicate that the connection is no longer available because of a temporary database problem. The Oracle SQLCODEs of 28, 3113, 3114 and so on indicate the same situation.

To provide portability for applications, WAS provides a DataStoreHelper interface to enable mapping of these codes to the WAS exceptions. The following code segment illustrates how to add two error codes into the error map...

public class NewDSHelper extends GenericDataStoreHelper
{
  public NewDSHelper()  
  {
    super(null);
    java.util.Hashtable myErrorMap = null;
    myErrorMap = new java.util.Hashtable(2);
    myErrorMap.put(new Integer(-803), myDuplicateKeyException.class);
    myErrorMap.put(new Integer(-1015), myStaleConnectionException.class);
    myErrorMap.put("S1000", MyTableNotFoundException.class);
    setUserDefinedMap(myErrorMap);
    ...
  }
}