• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Help needed ...User Transaction problem

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to using JTA...cannot conclude what's wrong the code here.
my goal is to do transaction commits and rollbacks at regular intervals.to put more detail
say..if I have a database table with only two columns(Key, Data) and given a array of 14 keys the records of which I want to update at regular intervals..
for example if the interval is 3
after updating records 1 to 3 ..I do a commit/rollback
after updating records 4 to 6 ..I do a commit/rollback
after updating records 7 to 9..I do a commit/rollback
after updating records 10 to 12..I do a commit/rollback
finally after updating records 13, 14 I do a commit/rollback

here's a code snippet..
UserTransaction ut = null;
int y = keyarray.size();
int i = 0; utinterval = 3;
while(i < y)
{
if(ut == null)
{ ut = mySessionContext.getUserTransaction();
ut.begin();
}
Statement updatest = conn.createStatement();
do update....
updatest.close();
if(i == utemp);
{
ut.commit or ut.rollback;
utemp = utemp + utinterval;
ut = mySessionCtx.getUserTransaction();
ut.begin();
}
}//end of while loop
ut.commit() or rollback.
I have tried doing this using DB2 and Oracle..
the problem is..
after I do a rollback if there is atleast one commit then the whole thing gets committed.
for example
for records 1 , 2, 3 after update I did rollback
for records 4, 5, 6 after update I did a rollback
for records 7, 8, 9 after update I did a commit
records 1, 2, 3, 4, 5, 6 all show the committed value.
I am not sure what's wrong with this code..
any advise/suggestion greatly appreciated.
-PP
 
Parthiv Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
wanted to add some more observations..
(Bean managed transactions, Websphere Studio Application Developer Test environment, DB2 UDB 7.2 )
To rephrase the problem...
all I am trying to do is
open a transaction
do some updates
close (commit/rollback) a transaction
Open a new transaction
do some updates
close a transaction
so on......
at regular intervals...
If I do rollbacks all the way down,i.e I do rollbacks for all transactions..then it works
but when I follow a Rollback with a Commit in the next transaction..it doesn't work, the rolled back update actually does a commit.
Can anyone help me out...THIS IS THE CRITICAL PATH in my project..and it is URGENT too..
Thanks in advance
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic