How can I place a lock on a single row?
First, not all databases support row level locks, so check the documentation for your DMBS. If you are using Oracle, you can issue a select...for update statement. Make sure your JDBC connection has autocommit turned off- otherwise, you'll get an ORA-01002- "Fetch out of sequence" error. Here's an example:
String cmd = "SELECT * FROM my_table WHERE my_column_a = criteria FOR UPDATE OF my_column_b"; ResultSet rset = stmt.executeQuery(cmd);Zac Corbiere adds
The important bit is the 'for update' tagged on the end.
String updateStmt = "update foo set bar="FUBAR" where current of " + rs.getCursorName();