• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How do you check is Result set is null

 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if (rs != null)
{
out.println("result set has got something");
while (rs.next())
{ //I am processing result set now
}
}
else
{
out.println("result set is empty");
}

IS THIS CORRECT WAY TO CHECK IF RESULT SET IS EMPTY,
FOR ME EVEN THOUGH RESULT SET IS EMPTY IT IS GOING
INTO FIRST BLOCK AND PRINTING
RESULT SET HAS GOT SOMETHING.
CAN SOMEONE ADVISE ME ON THIS
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there is a difference between resultset being empty & resultset being null.
If the resultset is empty it means that no rows were returned for the query & thats the reason the following line is executed.
out.println("result set has got something");
But I am sure "while (rs.next())" statement will print ("result set is empty");

Originally posted by Bhasker Reddy:
if (rs != null)
{
out.println("result set has got something");
while (rs.next())
{ //I am processing result set now
}
}
else
{
out.println("result set is empty");
}

IS THIS CORRECT WAY TO CHECK IF RESULT SET IS EMPTY,
FOR ME EVEN THOUGH RESULT SET IS EMPTY IT IS GOING
INTO FIRST BLOCK AND PRINTING
RESULT SET HAS GOT SOMETHING.
CAN SOMEONE ADVISE ME ON THIS


 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with Roopa.
you can try the method
boolean isEmpty(); in the Set interface (actually it is from the collection interface).
boolean isEmpty() Returns true if this set contains no elements.

Hope this help.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDBC is not part of the Programmer Certification objectives.
Sorry guys I'm moving this to JDBC forum..

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Get me the mayor's office! I need to tell her about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic