473,767 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi.

Given the following:

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

pStmt = conn.prepareSta tement(lockSubs criptionQuery);
pStmt.setLong(1 , a_Conference.ge tSubscriptionId ());
SqlHelper.execu tePreparedQuery (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 5667
<mi************ @yahoo.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Hi.

Given the following:

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

pStmt = conn.prepareSta tement(lockSubs criptionQuery);
pStmt.setLong(1 , a_Conference.ge tSubscriptionId ());
SqlHelper.execu tePreparedQuery (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
4295
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 with any definite answers. I would like to know if it is possible to use GetObject in order to read/write data between an ASP and an activeX application. VBS supports GetObject, so I thought ASP might, but I have not had any luck. ...
2
11360
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 the table during the REINDEX? I am working on a real-time application that handles over 2 million "events" per day and runs 7-by-24. Most of these events involve an UPDATE to one or two tables, though a small subset involve a bit more work. ...
3
3626
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 being stored correctly. Whenever I attempt to delete a row from my application I get the following error. SQL0911N The current transaction has been rolled back because of a deadlock or timeout. Reason code "68". SQLSTATE=40001
19
4108
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
4
6241
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 of message up front when they load records, than being told "updating failed" after they spend all the time entering their data. So here I am spending a lot of time trying to find a good
4
9608
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. To guarantee uniqueness of the application number SELECT FOR UPDATE statement is used. 2) Calculate new application number value.
1
8317
by: SrikanthSound | last post by:
Diff between pessimistic lock and optimistic lock
1
1543
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 seeing timeouts - Update query is holding the lock and the select statement is timing off. Now my question , how can I design this select statement so that it doesn't wait for this update to be commiitted - I do not want to run it with UR since...
3
3967
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
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9405
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10013
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9841
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7383
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.