• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transactions with Stored Procedures

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello my name is Alfonso
(forgive my poor English)


My problem is to update data in two different databases. One of the databases the update using a stored procedure but when there is a problem in implementing the rollback procedure does not make me, so I left half the transaction.

The implementation of this I use a session bean (spec 2.1) is the type of transaction using JTA bean type using the UserTransaction interface.

He was reportedly treated as separate transactions. To make sure the transaction use a control table where it stores the procedure if the operation is successful or not. If the transaction was not successful throw an exception and do a roolback.

The logic goes like this:

BeanSession {

public void methodA() {

UserTransaction utx = context.getUserTransaction();

try {

conn = getConnection();

utx.begin();

public void methodInsertHeader(conn, param1, param2,...) {}

public void methodInsertDetail(conn, param1, param2, ...) {}

public void executeStoredProcedure(conn, param1, param2, ...) {}

result = isProcedureSuccessful(){}

if (result != 0) throw new Exception

utx.commit();

} catch (Exception ex) {

utx.rollback();

}

}

}

Method description

public void methodInsertHeader(conn, param1, param2,..)

throws Exception {

try {

conn.prepareStatement(sql)

logic ...

} catch(Exception ex) {

throw new Exception("Error")

}

}


Is correct this?


Can you help in handling transactions

Greetings
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the the driver support two phase commit?
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic