-1

error image

java.sql.SQLException: Closed Connection: next

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:181) at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:2859)

Code

if (rs != null) {
    while (rs.next()) {
        resultset = Stmt.executeQuery();
        if (resultset.next()) {
            count += resultset.getLong(1);
            resultset.close();
            resultset = null;
        }
        Stmt.close();
        Stmt = null;
    }
}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
Vishal Mittal
  • 41
  • 1
  • 7
  • why set resultset to null after closing it? post more code as this seems to be right. also your connection seems to be closed. did you ever open one? – XtremeBaumer Jan 31 '17 at 14:51
  • Paste the error text, not an image. I don't appreciate clicking on links that take me god knows where. – duffymo Jan 31 '17 at 14:58
  • Possible duplicate of [Closed Connection: next in java](http://stackoverflow.com/questions/20497778/closed-connection-next-in-java) – code Jan 31 '17 at 15:40
  • Can you explain duplicate of Closed Connection @code – Vishal Mittal Jan 31 '17 at 16:51
  • @XtremeBaumer for more code here it is here rs and resulset both are diffrent `if (rs != null) { while (rs.next()) { resultset = Stmt.executeQuery(); if (resultset.next()) { count += resultset.getLong(1); resultset.close(); resultset = null; } Stmt.close(); Stmt = null; }` – Vishal Mittal Jan 31 '17 at 16:54
  • @VishalMittal Please update your question with the code snippet. Also, please provide the code snippets where `rs` is being initialized and closed. – code Jan 31 '17 at 17:01
  • Please don't provide code and error dumps alone. At least say a couple of sentences to describe your problem. – demongolem Jan 31 '17 at 17:16

1 Answers1

2

The error java.sql.SQLException: Closed Connection: next indicates that the resultSet is already closed when it is being used. Avoid closing the resultSet until it is guaranteed that it will not be used by the downstream code.

Looking at your code snippet, it looks like you are closing the Stmt instance withing the while loop and going to use it in the next iteration of the loop. That could be another reason for your issue. In that case, creating a new instance of the Stmt instance withing the loop should solve.

code
  • 2,283
  • 2
  • 19
  • 27