sjr59
sjr59

Reputation: 93

Resultset Exhausted Oracle query

I keep getting resultSet exhausted error on my JDBC java query. I know the queries themselves work because I have them in other methods, but for some reason the errors began popping up. I've been looking up how to fix this but nothing is helping. It is a one way query so first() and absolute() won't work. I'm not sure how it is getting past the while(result2.next()), is the result set is bringing back nothing(at the end of file). Any idea how to fix?

        command1 = "SELECT * from Foo WHERE (se = " + 
            result1.getInt("rec") + " OR rec = " 
            + result1.getInt("rec") + ")";          
        result2 = stat2.executeQuery(command1);             
        while(result2.next())
        {                   
            //this line is where the result set error pops up
            if(result2.getInt("rec") != result1.getInt("rec"))
            ...

Upvotes: 1

Views: 64

Answers (1)

Alexander Petrov
Alexander Petrov

Reputation: 9492

Use the following code:

String rec1 = result1.getInt("rec") 
command1 = "SELECT * from Foo WHERE (se = " + 
            rec1 + " OR rec1 = " 
            + rec1 + ")";          
        result2 = stat2.executeQuery(command1);             
        while(result2.next())
        {                   
            //this line is where the result set error pops up
            String rec2  = result2.getInt("rec")
            if(rec2 != rec1)

Once you have obtained a value from a result set in its scope, try to not access the same value from the results. Eventually of a particular results has been closed this exception will be raised when you try to access a value from it like you are doing for result1.getInt("rec")

Upvotes: 1

Related Questions