Example: Handling data access exception - error mapping in DataStoreHelper

WebSphere Application Server 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 WebSphere Application Server 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);
    ...
  }
}

[Fix Pack 27 or later] The userDefinedErrorMap custom property for data sources overlays existing entries in the error map by invoking the DataStoreHelper.setUserDefinedMap method. The userDefinedErrorMap can be used to add, change, or remove entries from the error map. For example, to remove the mapping of SQLState S1000, add a mapping of error code 1062 to duplicate key, and add a mapping of SQLState 08004 to stale connection, you can specify the following value for userDefinedErrorMap:
"S1000"=;1062=com.ibm.websphere.ce.cm.DuplicateKeyException;"08004"=
com.ibm.websphere.ce.cm.StaleConnectionException
userDefinedErrorMap can be located in the administrative console by selecting the data source and configuring the custom properties.



Related concepts
Exceptions pertaining to data access
Reference topic Reference topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 30, 2013 4:53:43 PM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-base-dist&topic=errmap
File name: rdat_errmap.html