ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/program/dataexp.htm

89 lines
4.8 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Data access exceptions</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h5><a name="dataexp"></a>Data access exceptions</h5>
<p>JDBC applications receive a standard SQLException if any JDBC operation fails.</p>
<p>The product provides special exceptions for its relational resource adapter (RRA), to indicate that the connection currently held is no longer valid:</p>
<ul>
<li><p><strong><a href="dataecwt.htm">ConnectionWaitTimeoutException</a></strong>
<br>This exception indicates that the application timed out trying to get a connection.</p></li>
<li><p><strong><a href="dataesce.htm">StaleConnectionException</a></strong>
<br>This exception indicates that the connection is no longer valid.</p></li>
</ul>
<p><strong>Error mapping</strong></p>
<p>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. Other database products use other SQLCODEs to indicate the same situation.</p>
<p>To provide portability for applications, WebSphere Application Server - Express provides a DataStoreHelper interface to enable mapping of these codes to the WebSphere Application Server - Express exceptions. In addition, WebSphere Application Server - Express enables you to plug in a data source that is not supported by WebSphere persistence. However, the data source must be implemented as either the XADataSource or the ConnectionPoolDataSource, and it must be in compliance with the JDBC 2.0 specification.</p>
<p>You can achieve application portability through the following:</p>
<ul>
<li><p><strong>DataStoreHelper interface</strong><br>
With this interface, each data store platform can plug in its own private data store specific functions that the relational resource adapter run time uses. WebSphere Application Server provides an implementation for each supported JDBC provider.</p>
<p>In addition, the interface also provides a GenericDataStoreHelper class for unsupported data sources to use. You can subclass the GenericDataStoreHelper or other WebSphere provided helpers to support any new data source.</p>
<p>For more information, see <a href="apidocs\ae\com\ibm\websphere\rsadapter\DataStoreHelper.html">Interface DataStoreHelper</a> <img src="api.gif" width="18" height="15" align="absbottom" alt="Go to API documentation"> in the Javadoc.</p>
<p>The following code segment illustrates how to add two error codes into the error map:</p>
<pre>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(&quot;S1000&quot;, MyTableNotFoundException.class);
setUserDefinedMap(myErrorMap);
...
}
}</pre>
<p>See the <a href="codex.htm">Code example disclaimer</a> for legal information about this code example.</p>
</li>
<li><p><strong>WSCallHelper class</strong><br>
With this class, applications can invoke any JDBC object proprietary methods that are not defined through the administrative console or standard APIs. This helper also enables applications to invoke many non-JDBC object methods.</p>
<p>All methods are static. For more information, see <a href="apidocs\ae\com\ibm\websphere\rsadapter\WSCallHelper.html">Class WSCallHelper</a> <img src="api.gif" width="18" height="15" align="absbottom" alt="Go to API documentation"> in the Javadoc.</p>
<p>The following code segment illustrates using this helper class (with a DB2 data source):</p>
<pre>
Connection conn = ds.getConnection();
// get connection attribute
String connectionAttribute =(String) WSCallHelper.jdbcCall(DataSource.class, ds,
&quot;getConnectionAttribute&quot;, null, null);
// setAutoClose to false
WSCallHelper.jdbcCall(java.sql.Connection.class,
conn, &quot;setAutoClose&quot;,
new Object[] { new Boolean(false)},
new Class[] { boolean.class });
// get data store helper
DataStoreHelper dshelper = WSCallHelper.getDataStoreHelper(ds);
</pre>
<p>See the <a href="codex.htm">Code example disclaimer</a> for legal information about this code example.</p>
</li>
</ul>
</body>
</html>