aspose file tools
The moose likes Servlets and the fly likes Using Datasource with and without transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Using Datasource with and without transaction" Watch "Using Datasource with and without transaction" New topic
Author

Using Datasource with and without transaction

Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
In a servlet, I have two methods that executes two different sql statements.
So from doPost, I use datasource.getConnection(), call first method, close the connection; again use datasource.getConnection(), call second method, close connection.
Now, how are these connections handled by pool when I wrap these method calls with usertransaction(s), and when donot use usertransaction at all?
I mean will these be two different physical/logical connections, and does it vary with/without usage of transactions?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Not sure what the answer to your question is but why are you using two connections in one method call?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2300
You will get a new connection from the pool and as far the transaction is concerned both the transactions would behave independently.


Rahul Bhattacharjee
LinkedIn - Blog
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
You will get a new connection from the pool and as far the transaction is concerned both the transactions would behave independently.


Is this new connection a logical/physical connection? Does it vary with and without usage of user transactions?

And when I donot use usertransaction.begin() and commit/rollback(), how are the transactions managed between these two methods?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Using Datasource with and without transaction
 
Similar Threads
Connection Pooling
Finding empty datasource in connection pooling
Data source
DriverManager or DataSource
Checking connection status