use ResultSet.TYPE_SCROLL_SENSITIVE -
this makes the "resultset sensitive to changes made while it is open. If the underlying column values are modified, the new values are visible, thus providing a dynamic view of the underlying data."
or use ResultSet.CONCUR_UPDATABLE -
"Updatable results sets may use write-only locks so that only one user at a time has access to a data item. This eliminates the possibility that two or more users might change the same data, thus ensuring database consistency. However, the price for this consistency is a reduced level of concurrency(largest number of simultaneous users allowed)"
The above quotes are from "JDBC API Tutorial and Reference, Second Edition" pp 586-587.
Jamie
Here is my code:
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
The error i got is:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Optional feature not implemented
Any thing i need to install ?...I am using jdk1.3
Yes, I exeperience the same always.
The MS ODBC driver seems not to support this.
But do you really need this for your logic?
Your origin question was not very specific.
Jamie's reply showed you one possibility. Not wrong at all, but I really wonder if there's any situation where you need this: a permanent logical relation between the data and a user who is working on them. For an online booking system or online trading evtl.?
I would follow DrClap's suggestion.
Hi Hartmut,
My situation is very simple. In my application, i have a popup which shows results of a query.If the user selects one record, i will display the full details in the background window. Now user can modify the fields and confirm the update.This is the operation.
Now assume after user1 has read and doing corrections, in the meantime user2 reads the same record and updates it quickly. Say, user2 has updated in db.
What happens to user1, when he/she comes for updating in the db ?(he/she is going to update the record without seeing the lattest version of it !!!)
I just want to give the user1, when he/she comes for updating the row, an alert like this...."Hey, the record is changed by someone else....Do you want to see the lattest ?"
Hope this explains my problem....
Clear. But this is no problem at all.
You have described very well the situation of concurrent update. (I have dealt with this first with COBOL on IBM CICS.)
2 possibilites:
1) Use transactions and lock the record for user1 the whole time. So user2 can't do his update - you get an exception from JDBC and tell it to the user, so he has to wait and retry then.
I would not do this for that long time.
(I think, this lock behaviour is called "pessimistic".)
2) Check before updating, what's now the actual content of the record in the db.
Use transactions for this:
* select // locks record
* check, if changed in the meantime since 1. select
* if not changed: update + commit // releases lock
* if changed: rollback // releases lock
(I think, this lock behaviour is called "optimistic".)
I'd recommend 2).
And some more to add to the above situation....friends...
Now i have a html, in which by clicking a button i am calling a servlet1 and showing the records in a popup. As the user selects a record from popup, i am closing the popup window and passing the record to base html.
After user makes some modifications, to confirm the changes, i am again calling servlet2.
In servlet2, again i am making a select query for the same row and verify the values to ensure that none has altered the record in the meantime.
So i need to carry the initial values from servlet1 to servlet2. But there is no straight connection between them. Can i make use of helper classes now?..will it work...?