Resultset has no method for hasNext. I want to check if the resultSet has any value
is this the correct way
if (!resultSet.next() ) {
System.out.println("no data");
}
Resultset has no method for hasNext. I want to check if the resultSet has any value
is this the correct way
if (!resultSet.next() ) {
System.out.println("no data");
}
Why not use rs.getRow()?
For me check "if (rs.getRow() != 0)" seems to work just fine.
Best to use ResultSet.next() along with the do {...} while() syntax for this.
The "check for any results" call ResultSet.next() moves the cursor to the first row, so use the do {...} while() syntax to process that row while continuing to process remaining rows returned by the loop.
This way you get to check for any results, while at the same time also processing any results returned.
By using resultSet.next() you can easily get the result, whether resultSet containing any value or not
you could always do the next up front, and just do a post loop check
The best thing for to do is to check the first row so that when you intend to get the data you can avoid the mistake of skipping a row. Something like: if (!resultSet.first() ) { System.out.println("no data"); }
Because if ResultSet has no raw then
resultSet.first
returns false.