ポータルの訪問者数 (オンライン、日次、週次、月次、年次) を表示する単純なポートレットがあります。
doView メソッドのポートレット クラスでは、最初にテーブルへの挿入を行う 1 つのメソッドを呼び出します (新しい訪問者に関する情報)。同じテーブルでカウント選択を行う5つのメソッドを1つずつ呼び出した後。それらはすべて非常に似ていますが、クエリのみが異なります。メソッドの実装の 1 つを次に示します。
public static Integer getOnline() {
Integer res = null;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = getConnection().createStatement();
rs = stmt.executeQuery(query);
if (rs.next()) {
res = new Integer(rs.getString("1"));
}
} catch (SQLException e) {
log.error("Excepton: " + e);
} finally {
if (rs != null) {
try { rs.close(); } catch (SQLException e) { log.warn("Error closing result set: ", e); }
rs = null;
}
if (stmt != null) {
try { stmt.close(); } catch (SQLException e) { log.warn("Error closing statement: ", e); }
stmt = null;
}
}
return res;
}
接続が取得されます。
public static Connection getConnection() {
try {
if (connection == null) {
if (dataSource == null) {
dataSource = (DataSource) new InitialContext().lookup(dataSourceName);
}
connection = dataSource.getConnection();
}
} catch (Exception e) {
log.error("Error on opening a connection: ", e);
}
return connection;
}
doView メソッドの最後で接続が閉じられます。時折、その例外が発生します:
com.ibm.db2.jcc.am.SqlException: [jcc][t4][10120][10898][4.14.88] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null
選択する1つまたはいくつかの方法から。また、時々次のエラー:
com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Connection is closed.
com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Statement is closed.
インターネットを検索した後、私の場合のエラーの原因とその修正方法をまだ見つけていません/認識していません。どんな助けでも大歓迎です。