• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to apply transactional insert is a scenario that 3 tables are going to change?

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thank you for reading my post
How i can apply transaction in a scenario like this :

In one of my web applicatinon page , i have 3 functions that each of them update/insert data to a table
I use connection pool to retrieve a connection in each of those functions (i can use one connection for all of functions but i do not know whether it is good or not).
Now the changes to database just should be applied if all of those functions insert data sucessfully.
my problem is that i do not know how i can use transaction in this case.

I need just the transaction over these inserts , which kind of commit mode i should use?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


(i can use one connection for all of functions but i do not know whether it is good or not


If you want to use JDBC transactions you will have to perform all three DB operations in one Connection. There isn't a way using JDBC alone to wrap the operations of three seperate Connections into one transaction.

If you can't change your code, you could wrap the call to these methods in a JTA transaction, presuming you have a transaction service you can use. It might be easier however (since this is a Servlet enviornment not an EJB environment) to fix your three methods to use one Connection.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic