+

Search Tips   |   Advanced Search

 

Example: Handling data access exception - error mapping in DataStoreHelper

 

WAS provides a DataStoreHelper interface for mapping different database SQL error codes to the appropriate exceptions in Application Server.

Error mapping is necessary because various database vendors can provide differing SQL errors and codes that might mean the same things. For example, the stale connection exception 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.

Mapping these error codes to standard exceptions provides the consistency that makes applications portable across different WAS installations. The following code segment illustrates how to add two error codes into the error map:

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





 

Related concepts


Exceptions pertaining to data access

 

Reference topic