ResultSet rs = stmt.executeQuery("SELECT * FROM employees"); while (rs.next()) { int rowNum = rs.getRow(); System.out.println("Row number: " + rowNum); }
ResultSet rs = stmt.executeQuery("SELECT * FROM employees"); while (rs.next()) { int rowNum = rs.getRow(); System.out.println("Row number: " + rowNum); if (rowNum == rs.last()) { break; } }In this example, the `getRow` method is again used to retrieve the row number for each row in the result set. The if statement checks if the current row is the last row in the result set using the `last` method of the `ResultSet` interface. If the current row is the last row, the while loop is exited using the `break` keyword. The ResultSet interface is part of the java.sql package, which provides classes and interfaces for accessing and managing a database.