Empty Resultset
How do I check for an empty resultset? I need to know if it contains any records before I try to read the fields and cause an error.
How do I check for an empty resultset? I need to know if it contains any records before I try to read the fields and cause an error.
> How do I check for an empty resultset?
if (!rs.next())
But you don't need to do that.
> I need to know
> if it contains any records before I try to read the
> fields and cause an error.
No, you don't.
while (rs.next()) {
String name = rs.getString("name");
// etc.
}
If it's empty, you'll never enter the body of the while loop.
Or, if it's one where you know there will only be one or zero rows, then use if instead of while.