我的代码抛出
java.sql.sqlRecoverableException: Sentencia cerrada: next
用英语来说,我想应该是:
java.sql.sqlRecoverableException: Closed statement: next
这是我的代码:
public TransactionArray() throws SQLException {
/* Obtenemos la tabla de transacciones. */
Connection connection;
connection = ConnectionManager.getConnection(STATISTIC_DATA_BASE);
Statement stmt = null;
String query =
"select * " +
"from " + "dCellStatistic" + ".F_Transaction";
ResultSet rs = null;
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(query);
} catch (SQLException e ) {
e.printStackTrace();
} finally {
if (stmt != null) { stmt.close(); }
}
/* Construimos las transacciones a partir de los registros. */
List<Transaction> transactionList = new ArrayList<Transaction>();
while (rs.next()) { //THE PROBLEM ARISES IN THIS LINE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
transactionList.add(new Transaction(rs));
}
array = transactionList.toArray(new Transaction[transactionList.size()]);
关于我可能做错了什么的任何线索?我在 Code Ranch 上看到了两个关于类似问题的线程,但它们似乎都没有为我的案例提供解决方案。
最佳答案
您在从结果集中检索信息之前关闭语句。在 rs.next()
循环之后移动 stmt.close()
调用(但保留 try/finally)。
关于java.sql.sqlRecoverableException : Closed statement: next 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14958165/