В классе портлета в методе doView сначала я вызываю один метод, который выполняет вставку в таблицу (информацию о новом посетителе). После того, как я вызываю 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;
}
Код: Выделить всё
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.
Подробнее здесь: https://stackoverflow.com/questions/152 ... sed-errorc