• Post Reply Bookmark Topic Watch Topic
  • New Topic

about JTA  RSS feed

 
kenshin Lin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody:
can someone tell me that how to use JTA without using EJB in J2EE
Environment?
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.transaction.UserTransaction userTransaction = null;
try{
userTransaction = context.getUserTransaction();
userTransaction.begin();
.......................
//operations inside the transaction
.......................
userTransaction.commit();
}catch(Exception e){
if(userTransaction != null) userTransaction.rollback();
....
}
Something like this.
 
kenshin Lin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sergiu truta:
thanks for yuor reply, but i want to know is "how to use JTA interface",
without "EJBContext" object in J2EE Environment.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"kenshin",
We don't have many rules here at the ranch but your display name is currently violating one of the few. You can change your display name here.
Thanks. And welcome to the JavaRanch!
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kenshin:
hi sergiu truta:
thanks for yuor reply, but i want to know is "how to use JTA interface",
without "EJBContext" object in J2EE Environment.

Do a JNDI lookup .
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you probably meant "Do a JNDI lookup of the UserTransaction".
Kyle
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
I think you probably meant "Do a JNDI lookup of the UserTransaction".
Kyle

Yes.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Context jndiCntx = new InitialContext();
UserTransaction tran =
(UserTransaction)jndiCntx.lookup("java:comp/UserTransaction");
utx.begin();
...
utx.commit();
I think you need to use the JNDI and JTA API, and most of the application servers bundle these relevant classes...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!