ResultSet rs = statement.executeQuery("SELECT * FROM employees"); while (rs.next()) { int rowNum = rs.getRow(); System.out.println("Row " + rowNum + ": " + rs.getString("name")); }
ResultSet rs = statement.executeQuery("SELECT id, name, age FROM students"); if (!rs.next()) { System.out.println("No students found."); } else { int rowNum = rs.getRow(); System.out.println("First student: " + rs.getInt("id") + " " + rs.getString("name") + " " + rs.getInt("age")); }This code retrieves the first row from the "students" table and prints the student's ID, name, and age. The java.util.ResultSet class and its getRow() method are part of the Java standard library, which is included in the java.util package.