Junior — Middle
How can it be determined whether a ResultSet contains any records?
sobes.tech AI
Answer from AI
To determine whether a ResultSet object contains any records, the next() method is usually called. This method moves the cursor to the next row and returns true if a row exists, and false if there are no more data.
Example check:
ResultSet rs = statement.executeQuery("SELECT * FROM table");
if (rs.next()) {
// At least one record exists
do {
// Process the current record
} while (rs.next());
} else {
// No records
}
Important: calling next() moves the cursor, so to process data after the check, you should use a loop or save the data.