美文网首页
Exception in thread "main" java.

Exception in thread "main" java.

作者: DuLaGong | 来源:发表于2019-09-25 21:22 被阅读0次

    好久不写简书了,今天遇到一个挺奇怪的问题,如下:

    ResultSet rs = stmt.executeQuery("select * from xxx");

    ResultSet rs2 = stmt.executeQuery("select * from xxx");

    int countWb =0;

    while (rs.next()) {

    countWb = rs.getRow();

    }

    while(rs2.next()){

    tradeDate=rs2.getString("xxx");

    }

    执行到while(rs2.next()){ 的时候就报Exception in thread "main" java.sql.SQLException: Statement has already closed.

    中间没有关闭Statement ,

    尝试修改代码顺序如下:

    ResultSet rs = stmt.executeQuery("select * from xxx");

    int countWb =0;

    while (rs.next()) {

    countWb = rs.getRow();

    }

    ResultSet rs2 = stmt.executeQuery("select * from xxx");

    while(rs2.next()){

    tradeDate=rs2.getString("xxx");

    }

    跑通成功,同一个stmt,执行完一次查询后,会关掉查询的入口,rs2.next()就会报错,所以rs2.next()运行之前在打开一次查询入口,即执行ResultSet rs2 = stmt.executeQuery("select * from xxx");

    就可以了。

    相关文章

      网友评论

          本文标题:Exception in thread "main" java.

          本文链接:https://www.haomeiwen.com/subject/ojbwuctx.html