Jump to Real's How-to Main page

Test for an empty ResultSet

  boolean found;
  ResultSet rs;
  ...      
  // execute the query and then
  found = rs.next();
  if (found)
      System.out.println("Record found");
  else
      System.out.println("RECORD NOT FOUND");
A nicer way to do the same would be
  
  ResultSet rs;
  ...  
  if (rs.next()) {
     do {
        System.out.println("Record found");
       } while (rs.next());
     }
  else {
     System.out.println("Record not found");
}

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]