Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes update table and syncornization 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 "update table and syncornization" Watch "update table and syncornization" New topic

update table and syncornization

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi all:
When trying to update a table in a database, disrgarding the database setting, do we need to syncorize the updata code?
for example:
connection = getConnection(true);
statement = connection.createStatement();
result = statement.executeUpdate(sql);}
[ April 13, 2004: Message edited by: Hanna Habashy ]

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
Locking, when it comes to DBs, is always better left to the Database. Consider the effect synchronized DB access will have on the performance of you application! Think why you would lock access when updating a row:
1. deadlock
2. race conditions
Deadlock is a very well understood problem in the world of RDBMSs. Its best left to them to handle possible collisions. Some are better then others (it takes more concurrent to cause a deadlock in Oracle than it does in SQL Server for example) but almost all are going to be better at handling this than you are in your code.
Race conditions are more common, since JDBC is usually used in a multiuser/multithread environment. In this case a locking startegy is a better route to protecting against the bugs race conditions can throw up. Optimistic locking works in most situations, and is a much better solution.
I agree. Here's the link:
subject: update table and syncornization
It's not a secret anymore!