Suppose that the table counts has five rows with the numbers 1 to 5. How many lines does this code print?
And that's the answer:
This code is tricky. While it does have two loops for the ResultSet, there is no call to the database in between. Therefore, the second call to setInt() is unused, and the second while loop does not iterate through any data. Only two lines are printed, making option C correct.
I can't understand why it says it prints two lines. For what I see the query is executed once and get just one line. So the first time rs.next() returns true and the result is printed, but the second time it returns false, and the second while loop is not executed.