473,382 Members | 1,302 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,382 software developers and data experts.

Lock issues in db2

Hi,

I'm new to DB2 and have little knowledge on database.

i'm facing a Spin lock issue in db2..

Thread here am talking is Java thread..(Sepearte process)

The spin Lock is acquired to ensure Same thread Can’t be stated again.
In our Application each thread is mapped to row .So lock is acquired on a row.

The issues in Db2.

1.We can acquire a Row Level Lock using for update. But it will release the lock when we use commit or rollback, we can’t use this because in our application we are doing multiple commits on that after acquiring a lock,,

2.There is another methodology available to achieve this is Cursor with Hold, if we use cursor with hold then it will maintain the lock even we used commit or rollback until we close the cursor.
So i try to implement this

We have multiple threads each thread have lock, So we need to Multiple cursor .Each cursor will hold a lock on each thread,..

The problem here is we don’t know how many number of threads required its dynamic so number of Cursor’s needed also Dynamic. (Each thread is to mapped to a cursor)
So we have to create a cursor Name Dynamically and close the same..
How to achieve this
1.Create 2 procedure one for acquire a lock (Create a cursor) and another to release the lock (Close the cursor)
2.Change the name of the cursor dynamically in the proc .


The Cursor Name creation dynamically using Java its failed Because Declare statement of Cursor can only be embedded in an application program. It is not an executable statement.
It must not be specified in Java. So i'm not proceeding to execute from java.

The option we have is to create a cursor name dynamically in a proc for acquiring and releasing the locks.

Sample Cursor :


CREATE PROCEDURE FCZ221k1.ACQURING_LOCK1 (IN RUNDATE CHAR , IN STREAMNO NUMERIC(10))
BEGIN
DECLARE C1_streamno CURSOR WITH HOLD FOR SELECT * FROM FCZ221K1.BatchProcessResult where rundate=RUNDATE FOR UPDATE;
Open C1_ streamno;
END;

Converted to Dynamic cursor name as per the example i found in net.

CREATE PROCEDURE FCZ221k1.ACQURING_LOCK1 (IN streamno VARCHAR(120) ,IN processdate VARCHAR(36) )
LANGUAGE SQL
BEGIN
DECLARE EX_IMMD_VAR2 VARCHAR(4000) ;
DECLARE EX_IMMD_STMT2 STATEMENT ;
BEGIN

SET EX_IMMD_VAR2 = 'CREATE CURSOR ' || cur_streamno || 'CURSOR WITH HOLD FOR SELECT * FROM FCZ221K1.BatchProcessResult where rundate=RUNDATE FOR UPDATE' ;
PREPARE EX_IMMD_STMT2 FROM EX_IMMD_VAR2 ;
EXECUTE EX_IMMD_STMT2;
END ;
End;

It’s also giving this error

SQL0312N The host variable "<host-name>" is used in a dynamic
SQL statement, a view definition, or a trigger
definition.

Explanation:

The host variable "<host-name>" appears in the SQL statement, but
host variables are not allowed in dynamic SQL statements, in the
SELECT statement of a view definition, or in the triggered action
of a trigger definition.

The statement cannot be processed.

User Response:

Use parameter markers (?) instead of host variables for dynamic
SQL statements. Do not use host variables and parameter markers
in view or trigger definitions.

sqlcode : -312

sqlstate : 42618

I’m not sure whether we can create a cursor name dynamically or not…

Please guide me on this…

Regards
Senthil
Jul 26 '08 #1
0 2787

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: n_o_s_p_a__m | last post by:
I have seen some debate but am not clear on what the problematic implications of the expression lock(this) are. Microsoft seems to advocate it, but others seem to be against it. Pros and cons? ...
0
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
2
by: Fernando Rodríguez | last post by:
Hi, I've been reading the multithreading tutorial at http://www.yoda.arachsys.com/csharp/threads/locking.shtml (thanks Jon :-) and there's one thing I don't understand. Why do have to pass a...
2
by: Kevin Frey | last post by:
Hello, I've been reading that ASP.NET serialises (ie. processes one at a time) HTTP requests if two simultaneous requests need to access the same session state. It also makes note that ASP.NET...
5
by: Bob Bins | last post by:
Is there a way to create a shared lock using the Monitor class or any other synchronization class in .NET? So I have one resource that may have multiple threads using it at once but a second...
4
by: misterutterbag | last post by:
Hi. Given the following: ---------------- String lockSubscriptionQuery = "SELECT subscriptionId FROM subscription WHERE subscriptionId = ? FOR UPDATE"; pStmt =...
7
by: Troels Arvin | last post by:
Hello, Some users are frustrated by DB2 locking their database operations (most recently: a table drop took forever, probably because of a lock). The natural and sane question I'm being asked:...
2
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will...
11
by: fritzcwdev | last post by:
I have a class as follows: public class OperationFeedback { DateTime _startTime; public DateTime StartTime { get {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.