aspose file tools*
The moose likes JDBC and the fly likes database row locking and update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "database row locking and update" Watch "database row locking and update" New topic
Author

database row locking and update

Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
when u have multiple users trying to update a record, how do u handle it -

1. do u handle it by writing codes (multiple threading) ?
2. or do u handle it from the database side, ie.e force the database to do locking ?

or do u do both 1) and 2) ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Frank,

JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

thanks,
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Frank,

If I take your question literally the answer is neither. Perhaps you could post what you want to achieve through this locking and describe a short scenario? That way we can advise you on the best approach. You certainly shouldn't be considering thread synchronisation in Java to achieve this.

Jules
Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
The scenario is simple --- The web tier offers customers chance to update some database information. Since it is possible that multiple users are online to update the database, I want to make sure that the database table (or row record) is locked when one user is updating, and that user should unlock it when he finishes. How to achieve this effect ? please provide some details. thanks,
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Do you select the data for the customer to update into the web tier first? That is, could two users be looking at/updating the same record at the same time? Is that what you're talking about? If so the optimum approach depends on how frequently you expect to get a collision. Frequent collisions require a pessimistic locking strategy; occasional/infrequent/rare collisions suggest an optimistic locking strategy would be most appropriate.

Jules
Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
Originally posted by Julian Kennedy:
Do you select the data for the customer to update into the web tier first? That is, could two users be looking at/updating the same record at the same time? Is that what you're talking about? If so the optimum approach depends on how frequently you expect to get a collision. Frequent collisions require a pessimistic locking strategy; occasional/infrequent/rare collisions suggest an optimistic locking strategy would be most appropriate.

Jules


julian, I feel you are the one who can give me the answers. Please, please continue on describing the details of optimistic and pessimistic locking methods. I want to know ---

1. what kind coding I need to do ?
2. what kind special SQL or database work I need to do ?

thanks
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Frank,

Of course I can give you the answers, but I'm not going to do the work for you. That's your job. If you answer my questions then maybe I can help further. I suggest you also search the web to help you to better understand the terms I've mentioned. If you run into trouble trying to implement one of the locking strategies or you feel you need further pointers I'd be happy to help.

Jules
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database row locking and update
 
Similar Threads
how do u do multiple updates in the database?
URLyBird 1.1.3, current issue with the "find()" method
How to persist a Collection using JDBC?
Locking dumb question
Record Locking