aspose file tools*
The moose likes JDBC and the fly likes do most databases writelock a row when it's changed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "do most databases writelock a row when it Watch "do most databases writelock a row when it New topic
Author

do most databases writelock a row when it's changed?

Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Hello,

I know that Oracle databases writelock a row when a value on it is changed, even if the "changed" value is the same as the old value, and the writelock is only released when the transaction is committed. Do all or most databases function the same way? I'm investigating the possibility of using JDBC w/ setAutoCommit(false) to synchronize distributed components.

Thank you,
Yuriy
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Originally posted by Yuriy Zilbergleyt:
Do all or most databases function the same way?

Yuriy,
Every database I used functioned that way. The database doesn't know that you are changing the value to the same value, just that it has been edited. In order to know there is no change, the database would have to go back through the transaction logs.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Thanks, Jeanne!

In that case there should be no problem with using JDBC as a synchronization mechanism among distributed components (like EJBs), right?

Thank you,
Yuriy
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Almost all databases will exclusively lock at LEAST the row you are updating/inserting but there is other behaviour that you may want to consider.

Many databases lock much more than the individual row. Some (like MS-SQL) lock the page (of allocated disk space containing the row) when they update rows. This means that several rows will be locked at the same time.

Further some other databases have to get exclusive locks on the whole table in order to make updates. (MySQL for one). This means that all the other rows in the table are locked (for writing) until finished.

I am not sure how you intend for your synchonization to work but I think you should be aware that yes the row you are updating will be locked but so possibly will many others get locked as well.
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
All right, thanks for the info Maximilian!

Yuriy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: do most databases writelock a row when it's changed?
 
Similar Threads
Using fair or unfair ReentrantReadWriteLock aquisition order ?
Concurrency issue with create(...)/createRecord(...) [URLyBird]
Clone a record in the database or element in an arrayList
synchronized(WhatIsThis)
JTABLE's valuchanged method?