Search code examples
jdbciteratorhsqldb

JDBC ResultSet: not last but has not next, why?


I am using HsqlDB 1.8.1, and found something strange:

ResultSet rs;
...
boolean isLast=rs.isLast();
assert !isLast;
boolean hasNext=rs.next();
assert hasNext;

In my case, isLast is false, but hasNext is also false! Can you tell me why? I think if the cursor is not on the last row of this resultset, then it should have next row.


Solution

  • I take it you meant that your hasNext assertion is failing because hasNext is false, correct?

    Is your ResultSet of type TYPE_FORWARD_ONLY? Per the documentation for ResultSet#isLast(), support for this method is "optional" in that case, though it's not clear whether it being optional means that the method will throw SQLFeatureNotSupportedException, or just return false unconditionally.