File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transactions with Stored Procedures" Watch "Transactions with Stored Procedures" New topic
Author

Transactions with Stored Procedures

Alfonso Rodr�guez
Greenhorn

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();

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
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Does the the driver support two phase commit?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
 
subject: Transactions with Stored Procedures