How can I find that the ResultSet, that I have got by querying a database, is empty or not?
How can I find that the ResultSet, that I have got by querying a database, is empty or not?
Immediately after your execute statement you can have an if statement. For example
ResultSet rs = statement.execute();
if (!rs.next()){
//ResultSet is empty
}
Do this using rs.next():
while (rs.next())
{
...
}
If the result set is empty, the code inside the loop won't execute.
Calculates the size of the java.sql.ResultSet:
int size = 0;
if (rs != null) {
rs.beforeFirst();
rs.last();
size = rs.getRow();
}
(Source)