File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Pessimistic Locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Pessimistic Locking" Watch "Pessimistic Locking" New topic
Author

Pessimistic Locking

Aryan Khan
Ranch Hand

Joined: Sep 12, 2004
Posts: 290

Hi all,
Is Pessimistic locking (SELECT...FOR UPDATE ) an ANSI standard or any other standard? Or they are specific extensions from database vendors?

Also can pessimistic locking be achieved using only JDBC API and not using "SELECT ....FOR UPDATE " as part of my queries.

Thanks
Aryan


OCP/MCP/SCJP/SCWCD/IBM XML/SCMAD/SCEA-1
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Originally posted by Aryan Khan:
Hi all,
Is Pessimistic locking (SELECT...FOR UPDATE ) an ANSI standard or any other standard? Or they are specific extensions from database vendors?

Also can pessimistic locking be achieved using only JDBC API and not using "SELECT ....FOR UPDATE " as part of my queries.

Thanks
Aryan


Pessimistic locking (and Optimistic Locking) are strategies for dealing with database collisions. They are best practices, not standards or vendor extensions.

You have to use Select for Update for pessimistic locking... however, keep in mind that pessimistic locking is not a scalable strategy. As you add users and transactions... wait for lock situations impact your transactions.
Aryan Khan
Ranch Hand

Joined: Sep 12, 2004
Posts: 290

Thanks Paul,
If they are not standards ..how can one ensure SQL portability. Many databases does not support "SELECT ...FOR UPDATE".
For concurrency and bottleneck, I agree!!!
Aryan
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you are just using JDBC, you'll need to provide per-database implementations for each pessimistic locking syntax. If you are using something like a DAO pattern this shouldn't have too much of an impact.

The alternative would be to use an ORM tool, which will give you portability without having to write per-dataabse code.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
jQuery in Action, 2nd edition
 
subject: Pessimistic Locking
 
Similar Threads
Concurrent updates does not throw any exception
How to tackle simultaneous updates done by different user to a single webpage
How can i explicitly lock a row of a Table
EJB-QL / findForUpdate methods
updating the database using Hibernate