java.sql.SQLException:ResultSet在sqlite上关闭 [英] java.sql.SQLException: ResultSet closed on sqlite

查看:102
本文介绍了java.sql.SQLException:ResultSet在sqlite上关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了很多答案,但不幸的是没有答案.我仍然无法弄清楚为什么我得到ResultSet closed.

I looked at many answers but unfortunately none answers my question and I still can't figure this out why I'm getting ResultSet closed.

这是导致问题的try代码段:

Here is the try code snippet that`s causing the issue:

        System.out.println(" System Info! @CHKMD5Files(): Found pre-existing details: "+TOTAL);

        Statement stmMD5 = null;
        Connection connMD5 = null;
        ResultSet rs_MD5 = null;
        String RESULTMD5 = null;

        try {
            connMD5 = DriverManager.getConnection("jdbc:sqlite:" + bkpPATH+ hostname + ".db");
            stmMD5 = connMD5.createStatement();
            connMD5.setAutoCommit(false);

            while (ROWID <= TOTAL) {
                rs_MD5 = stmMD5.executeQuery("SELECT md5 FROM details WHERE ROWID = '"+ROWID+"';");
                RESULTMD5 = rs_MD5.getString("MD5");
                skipBuffer.write(RESULTMD5);
                skipBuffer.newLine();
                skipBuffer.flush();
                ROWID++;
                }
            System.out.println(" System Info! @CHKMD5Files(): Done with try");

        } catch (Exception ex) {
            System.out.println(" System Error! @CHKMD5Files (2): " + ex);
            System.exit(5);
        } finally {
            if (stmMD5 != null){
                stmMD5.close();
                System.out.println(" System Info! @CHKMD5Files (2): Closing Statement(stmMD5)");
            }
            if (connMD5 != null) {
                connMD5.close();
                System.out.println(" System Info! @CHKMD5Files (2): Closing Connection(connMD5)");
            }
            skipBuffer.close();
        }
    }

看起来while循环甚至都不会运行,因为如果我将print语句放入循环中,则什么也不会返回.

Looks like the while loop does not even run because if I put print statement in the loop returns nothing.

推荐答案

非常感谢您的所有答复,并为我指出了正确的PATH,我已设法解决了该问题,这是因为ROWID开始时没有数据这就是造成我问题的原因.

Many Thanks for all your responses and for pointing me in the correct PATH I have managed to fix the issue and it was because the ROWID had no data at the start and that was causing me the issue.

检查是否为空的附加语句解决了我的问题:

The additional statement checking if it is empty resulved my issue:

                while (ROWID <= TOTAL) {
                rs_MD5 = stmMD5.executeQuery("SELECT md5 FROM details WHERE ROWID = '"+ROWID+"';");
                if (!rs_MD5.next() ) {
                    System.out.println(" System Info! @CHKMD5Files(): No data in rowid: "+ROWID);
                    ROWID++;
                } else {
                    RESULTMD5 = rs_MD5.getString("MD5");
                    skipBuffer.write(RESULTMD5);
                    skipBuffer.newLine();
                    skipBuffer.flush();
                    ROWID++;
                    rs_MD5.close();
                }
            }

这篇关于java.sql.SQLException:ResultSet在sqlite上关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆