aspose file tools*
The moose likes JDBC and the fly likes Checking for empty resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Checking for empty resultset" Watch "Checking for empty resultset" New topic
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: 1081

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking for empty resultset