I have to perform choose after which update a few of the rows within the ResultSet within an atomic way.

The code I'm using appears like (simplified):

stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("SELECT ...");

while (rs.next()) {
    if (conditions_to_update) {
        rs.updateString(...);
        rs.updateRow();
    }
}
  • Can One guarantee the updates will be performed atomically ? Otherwise, how could I ensure that ?
  • What goes on if every other process has transformed the database row that you're upgrading via updateRow() ? Can there be in whatever way to lock the rows within the ResultSet ?

There's most likely an entire heap of technologies and ideas that come up here, and things start getting fairly sticky when you begin thinking about multi-threaded / multi request programs.

As Iassevk mentioned, you need to consider using Transactions to guarantee the atomic character of the updates - a really low-level example is always to make a move like:

...
con.setAutoCommit(false);
try {
  while (rs.next()) {
    if (conditions_to_update) {
      rs.updateString(...);
      rs.updateRow();
    }
  }
  con.setAutoCommit(true);
} catch (Exception ex) {
  //log the exception and rollback
  con.rollback;
} finally {
  con.close();
}

All of the updates would then be batched in to the same transaction. If the updates produced the best (for example an invalid value or even the connection failing in the middle of the outcomes), the entire lot could be folded back. (Finally added because I'm a champion from it p )

Nevertheless this, will not address your next problem that is two competing techniques attempting to update exactly the same table - a race condition. You will find, i believe, two primary approaches here - each one has it's merits and disadvantages.

The simplest approach is always to Lock the table - this could require minimal code changes but includes a pretty large drawback. Focusing on the assumption that, associated with pension transfer programs, it's more read that write: securing the table may prevent other customers from viewing the information, using the likelihood the code will hang, awaiting the lock to produce prior to the connection time-out takes over and throws the best.

The greater complex approach is to make sure that the techniques for carrying out these updates are implemented inside a thread-safe manner. To that particular finish:

  • All of the updates with this table go through just one Class
  • That class implements a Singleton pattern, or exposes the update techniques as Static techniques
  • The update techniques utilise the Synchronized keyword to avoid race conditions

Use transactions.

"What goes on if every other process has transformed the database row that you're upgrading via updateRow() ? Can there be in whatever way to lock the rows within the ResultSet ?"

In Oracle, you are able to kinda mark certain rows for update by giving the next SQL.

choose cola, colB from tabA for update

The following transaction/thread/application that attempts to update this row can get the best. check this out for additional particulars -- http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4530093713805

Best Of Luck,

BR,
~A