java.sql.sqlexception下一个关闭连接

时间:2022-11-03 22:47:44

error image

java.sql.SQLException: Closed Connection: next

java.sql.SQLException:关闭连接:下一步

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)

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) )在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;
    }
}

1 个解决方案

#1


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.

错误java.sql.SQLException:Closed Connection:next表示在使用resultSet时它已经关闭。避免关闭resultSet,直到确保下游代码不会使用它。

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.

查看您的代码片段,看起来您正在使用while循环关闭Stmt实例,并将在循环的下一次迭代中使用它。这可能是您问题的另一个原因。在这种情况下,使用循环创建Stmt实例的新实例应该可以解决。

#1


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.

错误java.sql.SQLException:Closed Connection:next表示在使用resultSet时它已经关闭。避免关闭resultSet,直到确保下游代码不会使用它。

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.

查看您的代码片段,看起来您正在使用while循环关闭Stmt实例,并将在循环的下一次迭代中使用它。这可能是您问题的另一个原因。在这种情况下,使用循环创建Stmt实例的新实例应该可以解决。