Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.sqlRecoverableException: Closed statement: next

My code throws

java.sql.sqlRecoverableException: Sentencia cerrada: next

which, in English, I guess it would be:

java.sql.sqlRecoverableException: Closed statement: next

This is my code:

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()]);

}

Any clues of what I may be doing wrong? I have seen two threads on Code Ranch about similar issues, but none of them seemed to provide a solution for my case.

like image 761
Josep Avatar asked Feb 19 '13 13:02

Josep


1 Answers

You are closing the statement prior to retrieving the information from the result set. Move the stmt.close() call after the rs.next() loop (but keep the try/finally).

like image 107
Eric Galluzzo Avatar answered Nov 30 '22 06:11

Eric Galluzzo