File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Transactions with Stored Procedures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transactions with Stored Procedures" Watch "Transactions with Stored Procedures" New topic

Transactions with Stored Procedures

Alfonso Rodr�guez

Joined: Mar 31, 2008
Posts: 4
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();


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


} catch (Exception ex) {





Method description

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

throws Exception {

try {


logic ...

} catch(Exception ex) {

throw new Exception("Error")



Is correct this?

Can you help in handling transactions

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Does the the driver support two phase commit?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Transactions with Stored Procedures
It's not a secret anymore!