| Author |
Checking for empty resultset
|
Tom Joiner
Ranch Hand
Joined: Sep 19, 2006
Posts: 47
|
|
I am running a SQL query which is like this: And I want to check if the resultset is empty. Looking through the API here: http://java.sun.com/j2se/1.3/docs/api/java/sql/ResultSet.html I don't see the obvious solution. I can of course walk through the resultset twice, the first time counting it, and the second time using it, but this seems like a waste. Is there an API call that returns if it is empty?
|
SCJP
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
rs.next() returns false when the cursor can't move forward. So:
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Shailesh Chandra
Ranch Hand
Joined: Aug 13, 2004
Posts: 1076
|
|
Just want to add one thing when you call rs.next() takes you to first row, make sure you do not call rs.next() again until you have retrieved value of all columns of first row. Shailesh
|
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
|
 |
 |
|
|
subject: Checking for empty resultset
|
|
|