aspose file tools*
The moose likes JDBC and the fly likes update table and syncornization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "update table and syncornization" Watch "update table and syncornization" New topic
Author

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:
try
{
connection = getConnection(true);
syncornize(this){
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.
 
Don't get me started about those stupid light bulbs.
 
subject: update table and syncornization