This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes Table Locking and Unlocking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Table Locking and Unlocking" Watch "Table Locking and Unlocking" New topic
Author

Table Locking and Unlocking

Sahil Sharma
Ranch Hand

Joined: Aug 27, 2003
Posts: 152
Hi,

I need some help regarding Table Locking and Unlocking.
I am using mysql4.1 as my database and JDBC to connect to the same. Now I want to know that if
I lock a table using the Connection object and then close that same connection object without unlocking the table.
Will the locked table be released as soon as the connection is closed or will remain locked.

~Thanx
vu lee
Ranch Hand

Joined: Apr 19, 2005
Posts: 189
I am not sure that jdbc can lock a table. Suppose part of a transaction locks a row. If a connection is retrived from a connection pool, since close connection just returns it back to the pool, the row is not unlocked immediately. If a connection is created, closing connection will not release the lock immediately too. In either case, it's up to the database engine to release the lock.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42056
    
  64
Normally you don't lock tables (or pages or rows) explicitly; it happens implicitly if necessary. That means, if the table/page/row contains altered values within a transaction, it is locked against other changes. If the connection is closed without a commit, all changes are automatically rolled back and the locks are broken.
If you return the connection to the pool without a commit or rollback after you started a transaction, that's a serious bug on your part, and you can't expect predictable behavior afterwards.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Table Locking and Unlocking