我有一个比较简单的portlet,它显示门户(在线,每天,每周,每月,每年)的访问者数量。com.ibm.db2.jcc.am.SqlException:无效操作:结果集关闭。 ERRORCODE = -4470,SQLSTATE = null
在doView方法中的portlet类中,首先调用一个插入表的方法(有关新访问者的信息)。在我调用5个方法之后,在同一个表上进行计数选择。他们都非常相似,只是他们的查询有所不同。一个方法实施如下:获得
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
从一个或几个做选择的方法。有时也以下错误:
com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Connection is closed.
com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Statement is closed.
搜索我仍然没有发现互联网之后/意识到了什么是我的情况下,错误的原因,以及如何我可以修复它。任何帮助,将不胜感激。