• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • 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: 41146
848
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?
 
pie. 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
reply
    Bookmark Topic Watch Topic
  • New Topic