rspec/rules/S2232/java/rule.adoc
2021-04-28 18:08:03 +02:00

24 lines
747 B
Plaintext

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.
== Noncompliant Code Example
----
stmt.executeQuery("SELECT name, address FROM PERSON");
ResultSet rs = stmt.getResultSet();
while (! rs.isLast()) { // Noncompliant
// process row
}
----
== Compliant Solution
----
ResultSet rs = stmt.executeQuery("SELECT name, address FROM PERSON");
while (rs.next()) {
// process row
}
----