This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes 2 phase commit using UserTransaction without EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "2 phase commit using UserTransaction without EJB" Watch "2 phase commit using UserTransaction without EJB" New topic
Author

2 phase commit using UserTransaction without EJB

Vijay Bala
Greenhorn

Joined: Oct 25, 2001
Posts: 25
HI,
Is it possible to use 2 phase commit without using EJB ?
This is what i want to do:
1.
InitialContext ctx = new InitialContext();
javax.transaction.UserTransaction userTran = ctx.getuserTransaction();
try {
userTran.begin();
do updates to 2 distributed databases
userTran.commit();
} catch(Exception e) { userTran.rollback() }

2. Another optionI have seen is :
java.util.Properties env = ..
Context ctx = new IntialContext(env);
userTran = (userTransaction)ctx.lookup("java:comp/UserTransaction");
Rest of the code is the same.
Can i use such code in a simple helper class which is called by a servlet or does it have to be within a Session bean ? All i reallyw ant to do is geta UserTransaction instance and do updates to 2 databases within the transaction without using EJB ? I can't use EJB becoz the client doesn't want to use it.
Thanx,
Vijay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 phase commit using UserTransaction without EJB