aspose file tools*
The moose likes Servlets and the fly likes how to define a transaction in servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to define a transaction in servlets?" Watch "how to define a transaction in servlets?" New topic
Author

how to define a transaction in servlets?

kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
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

Joined: Aug 08, 2003
Posts: 135
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

Joined: Feb 16, 2001
Posts: 160
can someone tell me how to use JTA to create a transaction?is it just by using UserTransaction interface?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to define a transaction in servlets?
 
Similar Threads
best programming practises of JDBC
setRollbackOnly() related question
Closing Statement object prior to committing
Transactions!
Container Managed Transactions