I have this java code which does this
ResulSet rs = stmt.executeQuery();
while (rs.next()) {
.... //do regular processing
if (rs.last()) {
//do last record processing
}
}
I have this java code which does this
ResulSet rs = stmt.executeQuery();
while (rs.next()) {
.... //do regular processing
if (rs.last()) {
//do last record processing
}
}
Personally, I would declare the variables that are retrieved from the query outside the loop, and then do the "last record processing" after the loop.
ResulSet rs = stmt.executeQuery();
long primaryKey;
while (rs.next()) {
primaryKey = rs.getLong(1);
.... //do regular processing
}
// Do last record processing.
System.out.println("last primary key = " + primaryKey);
No: rs.last() will actually send the cursor to the last row in the ResultSet, which is definitely not what you want to do. You would only ever process at most 2 rows (first and last) from the result set.