Originally posted by Zhixiong Pan:
Hi ranchers,
I want to check if my ResultSet instance is empty of not, so I code this: if(!rs.next()) throw new EmptyWallException(); but that step will moves the cursor 1 row. In order to pull the cursor back, so I write expression rs.previous() and this will throw SQLException. At last I will have to re-create the ResultSet. Can anyone tell my why? Thank you.
Per default result sets are forward scroll only. If you want a scrollable result set, you must use a different createStatement method and specify that. Alternatively you can determine after the fact whether the set was empty or not by using a boolean set within the while(rs.next( ) ) loop, or, if you save information into arrays, or whatever, inside of the while loop, and checking, after the loop, whether the boolean was set, or data changed/added.