• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for empty resultset

 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rs.next() returns false when the cursor can't move forward. So:
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!