When you execute the request and get a ResultSet, I would say that at this moment you or even the program itself do not see how many results will be returned, this case is very similar to Oracle CURSOR, just declare Oracle what you want to do such a request, therefore, for each ResultSet we must get a row one by one to the last.
As already mentioned above, the guys answered: rs.last will iterate to the last, at this time the program has the ability to fully return the number of lines.
source share