1

resultset exhausted exception is occuring again and again ,i have checked all possibilities. my tables contain similar data but it is occuring.. i m pasting my code here.. please guide me

  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;
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Umer Sufyan
  • 156
  • 1
  • 8
  • *"i have checked all possibilities"* One possibility works, so obviously you haven't. BTW - Please add an upper case letter at the start of sentences. Also use a capital for the word I, and abbreviations and acronyms like JEE or WAR. This makes it easier for people to understand and help. – Andrew Thompson Nov 30 '13 at 04:22
  • All possibilities mean that i have tried my best but no gain – Umer Sufyan Nov 30 '13 at 04:24
  • Andrew Thompson please answer' – Umer Sufyan Nov 30 '13 at 04:30

1 Answers1

1

When working with regular results sets it is not possible to go back and forth as you do in your code. So when you run r.next() you cannot go to the previous value (and you do that several times). See this. You should refactor your code and put the values into variables that you can reuse.

Community
  • 1
  • 1
Artem Tsikiridis
  • 682
  • 6
  • 11