How to find whether a ResultSet is empty or not in Java?

Yatendra Goel picture Yatendra Goel · Feb 25, 2010 · Viewed 110.7k times · Source

How can I find that the ResultSet, that I have got by querying a database, is empty or not?

Answer

Paul picture Paul · Feb 25, 2010

Immediately after your execute statement you can have an if statement. For example

ResultSet rs = statement.execute();
if (!rs.next()){
//ResultSet is empty
}