LoginSignup
0
0

WebSphere Application Serverのデータ・ソース・カスタム・プロパティー userDefinedErrorMap を検証してみた

Last updated at Posted at 2024-02-15

検証方法

WAS 9.0 + DB2 の環境で、誤ったスキーマ名でSQLを実行すると、com.ibm.db2.jcc.am.SqlSyntaxErrorException SQLCODE=-204, SQLSTATE=42704が返ります。
このエラーを利用して設定を検証します。
まずは、このエラーについて userDefinedErrorMap の設定で Exceptionマッピングを StaleConnectionException に設定します。
次にtWAS 9.0 と Db2 で DataSourceを使うのWAS環境とDBを使って、testという誤ったスキーマ名でSQLを実行する以下のJSPを適当なWARの下に配置して実行します。

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*, javax.sql.*, java.lang.*, javax.naming.*" %>
<%
Context context=new InitialContext();
DataSource ds = (DataSource)context.lookup("jdbc/derbyEmbedded");
Connection con = ds.getConnection();

Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select id,name from test.EMPLOYEE");

st.close();
con.close();
%>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<p>Done</p>
</body>
</html>

検証1 エラー・コード

設定

userDefinedErrorMapにエラー・コードを設定。
-204=com.ibm.websphere.ce.cm.StaleConnectionException

検証結果

StaleConnectionExceptionがスローされるようになりました。

検証2 SQLSTATE

設定

userDefinedErrorMap にSQLSTATEを設定。*ダブルクォーテーションで設定する必要があります。
"42704"=com.ibm.websphere.ce.cm.StaleConnectionException

検証結果

StaleConnectionExceptionがスローされるようになりました。

どちらの検証でも、下記ページの記載通りの設定でExceptionマッピングを変更できることを確認できました。

[データ・アクセスに関する例外 - IBM Documentation]
( https://www.ibm.com/docs/ja/was-nd/9.0.5?topic=resources-exceptions-pertaining-data-access )

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0