There are several reasons to avoid ResultSet.isLast()
. First, support for this method is optional for TYPE_FORWARD_ONLY
result sets. Second, it can be expensive (the driver may need to fetch the next row to answer the question). Finally, the specification is not clear
on what should be returned when the ResultSet
is empty, so some drivers may return the opposite of what is expected.
stmt.executeQuery("SELECT name, address FROM PERSON"); ResultSet rs = stmt.getResultSet(); while (! rs.isLast()) { // Noncompliant // process row }
ResultSet rs = stmt.executeQuery("SELECT name, address FROM PERSON"); while (rs.next()) { // process row }