File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes can we use tx in servlets ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can we use tx in servlets ?" Watch "can we use tx in servlets ?" New topic
Author

can we use tx in servlets ?

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Hi all.
my servlet uses a datasource in order to get a connection to the database.
some code :

my question is can I do the following (inside the servlet) :
con.setAutoCommit(false);
// use multiple SQL insert & update
con.commit( );
I'm not sure if we can do this in a servlet...
any ideas ??
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Servlets are part of J2EE, so you can always get the UserTransaction from JNDI and manage your transaction yourself. At that point, you get your DataSource from JNDI and it magically joins the transaction, etc.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

So, I have to use UserTransaction ? right ?
I just want to be sure...
thanks.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
you don't have to but you can.
You can always use whatever transaction mechanism your drivers provide directly or roll your own.


42
 
jQuery in Action, 2nd edition
 
subject: can we use tx in servlets ?
 
Similar Threads
how to use a datasource that defined in Tomcat admin console inside a servlet
How to actually create a Datasource
JDBC 2.0 DataSource
why we need datasource
JDBC,JNDI,DataSource