search

How To Test For Empty ResultSet In Java


In theory, we set a String variable populated with “before” indicating that “results” have not been populated with .executeQuery yet.

Set a watch on the String variable. Set a breakpoint so you can see the variable populate with your “before” text. Set a breakpoint on the first line of the setters code so you can see the variable after .executeQuery is run.

Debug the app, stopping at the break points and then continuing after you view the watch results.

If you see “no_results” in the watch, you know the query is not working correctly and not bringing back the data (results is empty).  If you see “before” in the watch, you know that results has data (the query is working and bringing data back). This may indicate you have a problem with your setters. It could be the setter name, the database field name, or the data type.


String res = "before";  // create a variable and fill with 'before' // indicating it's before results are filled. this.results = ps.executeQuery(); // this.results.next(); if (!this.results.next()) {      // results is empty - it's not filled from the db query res = "no_results"  // fill the res variable with 'no_results' }
close
search

Hi, guest!

settings

menu