I've got a problem with using a SELECT ... FOR UPDATE.
The code basically looks like this (stripped down for simplicity):
PreparedStatement stat = conn.prepareStatement(
"SELECT ... FOR UPDATE",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE
);
try (ResultSet r = stat.executeQuery()) {
if (!r.next()) {
throw new Exception();
}
...
r.moveToCurrentRow();
r.updateString(column,value);
r.updateRow(); // throws SQLException
}
The call to updateRow() is throwing the following SQLException:
class java.sql.SQLException: Invalid cursor state - no current row.
I cannot for the life of me see why this is happening, since the test on
r.next() shows that I've found the row I want to update.
Can anyone suggest a reason what might be going on here?
Thanks,
--
John English