This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to define a transaction in servlets?

 
kriti sharma
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per jdbc 3 spec one jdbc connection forms one transaction. i.e. when we fetch a database connection via DataSource connection pooling of a application server like weblogic, all the sql statements will be commited when we close the connection. i hope i am right.

now if a methodA in a servlet makes multiple subsequent method calls, wherein each method call fetches its own database connection and performs sql statements; and it is required that either all methods called in methodA be successful together or none,i.e. methodA forms a single transaction, what should i do?use JTA UserTransaction?
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way:

Use the same Connection object. Call connection.getAutoCommit(false). Call connection.commit() when your transaction(as defined by you) is complete.
[ August 04, 2004: Message edited by: Rovas Kram ]
 
kriti sharma
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone tell me how to use JTA to create a transaction?is it just by using UserTransaction interface?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic