473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Does DB2 v 8.1 need UPDATE to get a pessimistic lock?

Hi.

Given the following:

----------------
String lockSubscriptionQuery =
"SELECT subscriptionId FROM subscription WHERE subscriptionId = ?
FOR UPDATE";

pStmt = conn.prepareStatement(lockSubscriptionQuery);
pStmt.setLong(1, a_Conference.getSubscriptionId());
SqlHelper.executePreparedQuery(pStmt);
pStmt.close();
-----------------

Q1: Will the last close() release the pessimistic lock?

Q2: My understanding was that SELECT...for UPDATE got a pessimistic
lock. But my tests show I need to UPDATE the row just after to get the
lock.

Q: Should we close the statement later if we want to hold the lock for
longer?

The following URL
http://java.sun.com/j2se/1.4.2/docs/...nt.html#close()

Says "Releases this Statement object's database and JDBC resources
immediately...."

Wondering what DB2 will do. How to get a pessimistic lock? etc....

Any help would be greatly appreciated. Thanks.

Joel

Sep 8 '06 #1
4 5640
<mi************@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi.

Given the following:

----------------
String lockSubscriptionQuery =
"SELECT subscriptionId FROM subscription WHERE subscriptionId = ?
FOR UPDATE";

pStmt = conn.prepareStatement(lockSubscriptionQuery);
pStmt.setLong(1, a_Conference.getSubscriptionId());
SqlHelper.executePreparedQuery(pStmt);
pStmt.close();
-----------------

Q1: Will the last close() release the pessimistic lock?

Q2: My understanding was that SELECT...for UPDATE got a pessimistic
lock. But my tests show I need to UPDATE the row just after to get the
lock.

Q: Should we close the statement later if we want to hold the lock for
longer?

The following URL
http://java.sun.com/j2se/1.4.2/docs/...nt.html#close()

Says "Releases this Statement object's database and JDBC resources
immediately...."

Wondering what DB2 will do. How to get a pessimistic lock? etc....

Any help would be greatly appreciated. Thanks.

Joel
A "select for update" will take a lock on the row, but that kind of lock
does not prevent selects from other applications. It will only prevent other
select for updates, updates, or deletes of that row by other applications.
To get an exclusive lock that will prevent even reads from other
applications you need to update it or delete it without a commit.

All locks are released when a commit or rollback happens. I don't know
enough about Java to say it the pStmt.close() issues a commit.

Remember that for locking purposes, only other applications are locked out,
and other SQL statements in the same application are not locked out by their
own previous SQL statements.
Sep 8 '06 #2
Q1: Will the last close() release the pessimistic lock?
No you need to either commit, rollback, or release to release locks.
Paul
Sep 9 '06 #3
Check if your version of the USE AND KEEP UPDATE/EXCLUSIVE LOCKS in the
isolation clause. It was introduced in DB2 V8.2 I believe
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 9 '06 #4
Thanks very much.

That was a big help.

-Joel

Sep 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Rich | last post by:
Hello, I have not been working with ASP for too long at this time and am not real familiar with a lot of things about ASP. I have searched for articles on the following question but not come up...
2
by: G.W. Lucas | last post by:
I apologize if this is a RTFM question, but I have not been able to find a definitive answer elsewhere. Does a "REINDEX TABLE" lock the table while it is working? Can applications write data to...
3
by: Ray | last post by:
I am having my first experience using BLOB as a row in a table. I am using it to insert graphics for labels we print. I have no problem inserting into and select from the table. The graphic is...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
4
by: feng | last post by:
Hi, I know ADO.Net recommand using disconnected update (optimistic concurrency) for good reasons, but it's just not an option for us. 99% of our clients would rather seeing "record locked" kind...
4
by: pike | last post by:
DB2 UDB 8.1 FP7 We are getting intermittent deadlocks (911 RC 2) even when U row-lock has been secured. The transaction is as follows: 1) Select current application number value from table....
1
by: SrikanthSound | last post by:
Diff between pessimistic lock and optimistic lock
1
by: contactrajib | last post by:
I have a situation where one of the app server thread is executing an update statement on A record and at the same time another thread is trying to read it by executing a select query. Now we are...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.