Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

2 phase commit using UserTransaction without EJB

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to use 2 phase commit without using EJB ?
This is what i want to do:
InitialContext ctx = new InitialContext();
javax.transaction.UserTransaction userTran = ctx.getuserTransaction();
try {
do updates to 2 distributed databases
} 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.
See where your hand is? Not there. It's next to this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
    Bookmark Topic Watch Topic
  • New Topic