I know that I can update one record like this, but how do I access the ID of the updated record? (I use MSSQL, so I can not use Orales RowId)
update myTable
set myCol = 'foo'
where itemId in (select top 1 itemId from myTable )
If I formatted Insert, I could use getGeneratedKeys to get the id field value, but I don’t think there is an equivalent for updating?
I know that I can use a scrollable result set to do what I want
i.e.
stmt = conn.prepareStatement("select top 1 myCol, itemId from myTable", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet resultSet = stmt.executeQuery();
if(resultSet.first()){
resultSet.updateString(1, "foo");
resultSet.updateRow();
String theItemId = resultSet.getString(1)
}
resultSet.close();
but performance bothers me, as testing shows lockout timeouts under load, and I was wondering if there was a better / easier way?
- EDIT:
...
MSSQL2005, , Rich-.
: (UPDLOCK ROWLOCK READPAST), , .