473,890 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT ... FOR UPDATE not locking rows

Hello.

We have a multi-user Java application that can connect to either a
UniVerse database or a DB2 database on an AS400 through JDBC. The
program executes a SELECT ... FOR UPDATE statement. When connected to
the UniVerse database, if a second user runs the program, at the point
where the selection executes, the program waits on the lock until the
first user's updates are committed. However, when connected to the DB2
database, in the same situation, execution proceeds as if the FOR
UPDATE were not there.

Any ideas on what I should be looking for? Thanks.

Mar 21 '07 #1
3 28683
jb*********@sbc global.net wrote:
Hello.

We have a multi-user Java application that can connect to either a
UniVerse database or a DB2 database on an AS400 through JDBC. The
program executes a SELECT ... FOR UPDATE statement. When connected to
the UniVerse database, if a second user runs the program, at the point
where the selection executes, the program waits on the lock until the
first user's updates are committed. However, when connected to the DB2
database, in the same situation, execution proceeds as if the FOR
UPDATE were not there.

Any ideas on what I should be looking for? Thanks.
See the definition of update-clause here:
http://publib.boulder.ibm.com/infoce...zmstintsel.htm

Excerpts:
"The UPDATE clause identifies the columns that can be updated in a
subsequent positioned UPDATE statement."
"When FOR UPDATE is used, FETCH operations referencing the cursor
acquire an exclusive row lock."

--
Karl Hanson
Mar 21 '07 #2
On Mar 21, 3:17 pm, Karl Hanson <kchan...@youes s.ibm.comwrote:
jbutler8...@sbc global.net wrote:
Hello.
We have a multi-user Java application that can connect to either a
UniVerse database or a DB2 database on an AS400 through JDBC. The
program executes a SELECT ... FOR UPDATE statement. When connected to
the UniVerse database, if a second user runs the program, at the point
where the selection executes, the program waits on the lock until the
first user's updates are committed. However, when connected to the DB2
database, in the same situation, execution proceeds as if the FOR
UPDATE were not there.
Any ideas on what I should be looking for? Thanks.

See the definition of update-clause here:http://publib.boulder.ibm.com/infoce...ndex.jsp?topic...

Excerpts:
"The UPDATE clause identifies the columns that can be updated in a
subsequent positioned UPDATE statement."
"When FOR UPDATE is used, FETCH operations referencing the cursor
acquire an exclusive row lock."

--
Karl Hanson
Thanks. I'm not sure this is the exact solution you were pointing me
toward, but adding an isolation clause WITH RR to the select when
connected to DB2 did the trick.

Mar 21 '07 #3
On Mar 21, 9:08 pm, jbutler8...@sbc global.net wrote:
On Mar 21, 3:17 pm, Karl Hanson <kchan...@youes s.ibm.comwrote:


jbutler8...@sbc global.net wrote:
Hello.
We have a multi-user Java application that can connect to either a
UniVerse database or a DB2 database on an AS400 through JDBC. The
program executes a SELECT ... FOR UPDATE statement. When connected to
the UniVerse database, if a second user runs the program, at the point
where the selection executes, the program waits on the lock until the
first user's updates are committed. However, when connected to the DB2
database, in the same situation, execution proceeds as if the FOR
UPDATE were not there.
Any ideas on what I should be looking for? Thanks.
See the definition of update-clause here:http://publib.boulder.ibm.com/infoce...ndex.jsp?topic...
Excerpts:
"The UPDATE clause identifies the columns that can be updated in a
subsequent positioned UPDATE statement."
"When FOR UPDATE is used, FETCH operations referencing the cursor
acquire an exclusive row lock."
--
Karl Hanson

Thanks. I'm not sure this is the exact solution you were pointing me
toward, but adding an isolation clause WITH RR to the select when
connected to DB2 did the trick.- Hide quoted text -

- Show quoted text -
Hi,

Did this really do the trick?

The reason I ask is that we have also experienced deadlocks between
two instances of the same code that uses a cursor to ensure the record
is locked prior to any processing.

The row is identified using the PK of the table, so only one row is
ever identified and hopefully locked and tracing confirms that both
processes were using the same primary key. My understanding of the FOR
UPDATE clause and FETCH, was that one process would wait for the
other, however DB2 does not appear to behaving this way (at least not
in v8.2.5 anyway).

You may have solved our problem if it is true.

Regards,
Paul.

Mar 27 '07 #4

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

Similar topics

0
1344
by: Andy Jackman | last post by:
Hi, I want to get any one of a number of rows that matches some criteria and update it so that it is marked as 'mine'. How can I do this safely? Given something like this table: create table tbl_new ( t_value varchar(16) primary key not null, dt_used datetime, l_pid int(9)
5
3857
by: jayson_13 | last post by:
Hi, I need to implement a counter and i face problem of locking so hope that u guys can help me. I try to do test like this : 1st connection SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update; (when i execute this statement and i guess that this will lock the
0
1354
by: Steve Crawford | last post by:
In one system I have a table of work to be done (for simplicity in this explanation I'll use a table consisting of id and status). A client-side app needs to fetch 10 available items from the table but naturally we don't want two clients working on the same 10 items. My first attempt at handling this was, in pseudocode: begin transaction select * from worktodo where status = 0 limit 10 for update
3
5590
by: charles | last post by:
I've got maybe a stupid question, concerning the difference between a simple select and a select for update ( otherwise identical ). The plan for such selects - in a DPF enviropnment - are completely different. Hash joins are used and the select without update returns fairly quickly, while the select for update involves large nested loop joins. Am I missing some obvious point about why a hj would not be used in a select for update?
29
2151
by: Geoff Jones | last post by:
Hi All I hope you'll forgive me for posting this here (I've also posted to ado site but with no response so far) as I'm urgently after a solution. Can anybody help me? I'm updating a table on a database i.e. I've modified the table in a DataSet and I want to update it to the SQL database which the table originally came from. I'm using a data adaptor and the update command and it works BUT it is soooooooooo slow!!! Can anybody tell me...
4
11318
by: Nick Barr | last post by:
Hi, I am trying to gather stats about how many times a resource in our web app is viewed, i.e. just a COUNT. There are potentially millions of resources within the system. I thought of two methods: 1. An extra column in the resource table which contains a count. a. Each time a resource is viewed an UPDATE statement is run.
4
4096
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement this function using select-for-update (or equivalent) in order to get a row-level lock (and thus less contention) while maintaining the function interface? The docs seem to suggest so, but it's not clear how to return the SETOF queued_item and also...
5
3414
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character text field. I want to know which Data type I need to use so that it doesnt waste memory. thanks in advance, rAinDeEr
5
8351
by: parwal.sandeep | last post by:
Hello grp! i'm using INNODB tables which are using frequently . if i fire a SELECT query which fetch major part of table it usually take 10-20 seconds to complete. in mean time if any UPDATE qry comes for a perticular row which is part of SELECT qry i want to know that whether UPDATE will wait for completing SELECT qry or not, or it simply executing without bothering SELECT qry .
0
9810
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
11207
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
10794
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
10443
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...
0
7153
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5830
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
6031
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4652
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
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.