If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > savepoint in DB2 sqlj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-07, 01:51
udaysaw udaysaw is offline
Registered User
 
Join Date: Mar 2007
Posts: 2
savepoint in DB2 sqlj

Hi,
we have a SQLJ procedure which inserts and commits after every 300 rows
with autocommit set as false.
requirement is that if there is an error in any record, only that insert should be rollbacked keeping earlier record inserts and once 300 record inserts are over, it should commit.
We created savepoint before every record insert.since it does not allow us to create a savepoint even with diff. name when there is one already existing (error savepoint already exists and nested savepoints not supported), we released savepoint (from record #2 onwards) and recreated before insert start.
If we get an error during insert, we rollback to the latest savepoint created before insert and fire a commit after batch commit frequency is reached (Eg. 300) .
Expected result is all records except the erroroneous one should get inserted.
But to our surprise none of the records were inserted.
Logic of our program is such that,
there is a controller/Main SQLJ which calls processing SQLJ for every record and we tried savepoint creation, release and rollback in the processing SQLJ.
Version : for testing, DB2 V7.1 on sun solaris unix box.
requirement on DB2 V7.1 on mainframe os/390
Can anyone please help in this regard.
Reply With Quote
  #2 (permalink)  
Old 03-10-07, 04:31
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
If it was on mainframe Host programming language i could have done this way. If you get any error while inserting write that record to error file and go ahead with the insert process.

INSERT RECORD
IF SQLCODE <> 0 THEN WRITE to error file.
(Or check for particular sqlcode as per the requirement)

I dont have any idea about SLQJ. But i believe it is used for executing static sql. If you have an option of writing to error file then you can go for it. At the end of the batch you can investigate on error records.
__________________
Vinay,
Reply With Quote
  #3 (permalink)  
Old 03-11-07, 10:22
udaysaw udaysaw is offline
Registered User
 
Join Date: Mar 2007
Posts: 2
Quote:
Originally Posted by vini_srcna
If it was on mainframe Host programming language i could have done this way. If you get any error while inserting write that record to error file and go ahead with the insert process.

INSERT RECORD
IF SQLCODE <> 0 THEN WRITE to error file.
(Or check for particular sqlcode as per the requirement)

I dont have any idea about SLQJ. But i believe it is used for executing static sql. If you have an option of writing to error file then you can go for it. At the end of the batch you can investigate on error records.
Thanx for the reply..
But for every record, there are multiple inserts in different tables and all of these have to be atomic. i.e. either all or none. so if we get an error in any one insert, need to rollback all inserts for that record. Hence we need help on savepoint. I just wanted to check with it works with DB2 V7.1 on mainframe.
Reply With Quote
  #4 (permalink)  
Old 03-11-07, 12:57
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by udaysaw
requirement is that if there is an error in any record, only that insert should be rollbacked keeping earlier record inserts
In that case I would propose to just either commit or rollback after every group of inserts that go together, depending on the return codes received.
After all, that's what commits & rollbacks are for: to define "logical units of work", and in your application your units of work consist of the inserts that form an atomic set.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 03-12-07, 04:06
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
Exactly, Put all Multiple inserts to a different tables in a Single Logical unit of work.
On mainframes, ATOMIC can be achieved by putting a COMMIT or ROLLBACK after the set of statements are executed successfully. if all the inserts are successfull put a commit at the end of unit. You have to check for sqlcode of each and every sql statement as mentioned by Peter.

If some thing goes wrong in between then can rollback to the latest savepoint or if you can handle that, it would be good.
__________________
Vinay,
Reply With Quote
  #6 (permalink)  
Old 03-12-07, 14:33
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
An alternative is to use atomic compound statements:
Code:
BEGIN ATOMIC
   INSERT ...;
   INSERT ...;
   INSERT ...;
END
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On