File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Lock while Updating? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Lock while Updating?" Watch "Lock while Updating?" New topic

Lock while Updating?

Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
In SQL server if the program is updating a row and at the same time if a program is trying to read that particular row which is being updated then what happens assuming that the transaction level is set to read_committed.
Will there be a lock and the thread try to read that row will wait till the lock is released or will it read the previous data of the row and display it to the user? What happens if the transaction is set to read_uncommitted?

Similarly what happens if 2 threads are trying to update the same row at the same time?
S Herod

Joined: Apr 25, 2005
Posts: 10
Well, it will depend on your database implementation but..

I believe 'read commited' usually means 'Show me only rows who's changes have been committed to the database'

So, if you try a read a row whilst a write is taking place, you will see the data prior to the write, until the row change is committed.

But really, you don't want JDBC's semantics for this, you want the underlying db's implementation of how it works.
I agree. Here's the link:
subject: Lock while Updating?
It's not a secret anymore!