【问题标题】:Exception resultset exhausted is occuring again and again异常结果集耗尽一次又一次发生
【发布时间】:2013-11-30 04:21:07
【问题描述】:

结果集耗尽异常一次又一次发生,我已经检查了所有可能性。我的表包含类似的数据,但它正在发生..我在这里粘贴我的代码..请指导我

  ArrayList<Duty> myList = new ArrayList<Duty>();
    try {

        String query = "select * from CBMS.DUTIES";
        ResultSet r = con.statement.executeQuery(query);

        while (r.next()) {
            Centre c = null;
            Teacher t = null;
            query = "select * from CBMS.center";
            ResultSet r1 = con.statement.executeQuery(query);

            while (r1.next()) {

                if (r.getInt(2) == r1.getInt(1)) {
                    c = new Centre(r1.getString(3), r1.getInt(1), r1.getString(2));
                    break;
                }
            }

            query = "select * from CBMS.teacher";
            ResultSet r7 = con.statement.executeQuery(query);
            while (r7.next()) {
                System.out.println(r7.getString(1));
                if (r.getInt(3) == r7.getInt(2)) {
                    t = new Teacher(r7.getString(1), r7.getInt(2), r7.getString(3), r7.getString(4), r7.getString(5));

                    break;
                }
            }


            Duty d = new Duty(c, t, r.getString(4), r.getInt(1));
            myList.add(d);
        }

    } catch (Exception e) {

        System.out.println(e.getMessage());
    }
    return myList;

【问题讨论】:

  • “我已经检查了所有可能性” 一种可能性有效,所以显然你没有。顺便说一句 - 请在句子的开头添加一个大写字母。还要为单词 I 使用大写字母,以及 JEE 或 WAR 等缩写词和首字母缩略词。这使人们更容易理解和帮助。
  • 所有可能意味着我已经尽力了,但没有收获
  • 安德鲁汤普森请回答'

标签: java sql resultset


【解决方案1】:

使用常规结果集时,无法像在代码中那样来回切换。因此,当您运行 r.next() 时,您无法返回之前的值(并且您会多次这样做)。见this。您应该重构代码并将值放入可以重用的变量中。

【讨论】:

    猜你喜欢
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    相关资源
    最近更新 更多