aspose file tools*
The moose likes JDBC and the fly likes Transaction handling in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Transaction handling in JDBC" Watch "Transaction handling in JDBC" New topic
Author

Transaction handling in JDBC

Shubhashis Dasgupta
Greenhorn

Joined: Jul 27, 2001
Posts: 9
Hi all,
I have a question regarding transaction management in a JSP-Servlet-Javabean (MVC) arch. I have written a connection pool class and getting free connections from the pool wherever needed. I have some business objects like user, application etc(Object-Relational mapping). Those are not EJBs but I have written entire jdbc code in those business objects to handle create, update, remove or find operations. Now my problem is, I have to handle transaction within a client servlet which creates, updates and deletes some record from separate table thru those business objects, since the business objects use separate connection objects from pool I am not being able to handle the transaction using commit and rollback methods of connection.
Does anybody have a soln. for this?
Shubhashis
A Agrawal
Ranch Hand

Joined: Jul 13, 2001
Posts: 41
Hi...
Actually You would need to change your architecture a bit...In case of Transaction don't return the connection back to pool, keep it in some hashtable [maintained by a singleton (i.e. single instance class) on server] keeping some ID (say ContextId) as key and connection as value.
maintain this ContextId at client end...next time you need the connection to continue/commit/rollback the transaction, take it from the hashmap on the basis of Id your client prgm is passing.
do watever you want to do with this connection and return it to the pool only when you are done.
and yes don't forget to turn autocommit property false before you start using connection for a transaction. also keep contextid unique.
hope this helps.

------------------
Amit Agrawal,
New Delhi, India.
[This message has been edited by A Agrawal (edited August 16, 2001).]


Amit Agrawal,<BR>New Delhi, India.
 
Consider Paul's rocket mass heater.
 
subject: Transaction handling in JDBC
 
Similar Threads
DB Connection from EJB: CachedConnectionManager
Advise if I am in correct direction
JDBC in JSP/Servlet question
long post IBM.158
EJB and DAO transaction question