File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Checking table locks in java 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 "Checking table locks in java" Watch "Checking table locks in java" New topic

Checking table locks in java

arabinda baas

Joined: Jun 23, 2008
Posts: 2
Hi all,

i have a problem like, lets say a database table is locked in shared mode.
At that time another thread is trying to put Exclusive lock on it.
so my question is how can you check the type of lock present on a particular table. If we can find out that there is already some lock present on a table, then we can make the second thread to wait for the lock to be released.

Any input on the same will be helpful.

prakash chandra

Joined: Aug 14, 2007
Posts: 24
i think this cannot be solved in java... still then i am trying to find a solution...

SCJP 6.0
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You would need to use the database specific stored procedures or views provided by your RDBMS. For example, SQL Server has sp_lock that will give you meta data one the lock. Oracle has v$lock. Check your RDBMS docs.

However, given your requirement, it might be better to catch the SQLException, parse it for the known SQL error code (or whatever) and sleep if it is an locking exception.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
arabinda baas

Joined: Jun 23, 2008
Posts: 2
thanks a lot for replying.
i am using informix db.
catching the exception seems to be the easier one.
as java api says getErrorCode() method will display the vendor specific error codes.
Can it happen like informix team uses same error codes for different errors.
I agree. Here's the link:
subject: Checking table locks in java
It's not a secret anymore!