Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How can I rollback when connection close?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I work with Oracle (jbdc) in web developpment.
Presently with java, when we close the Oracle Connection, a commit is made automatically.
I want to change it to an automatic rollback when I close the connection (myConn.lose() ).
The reason is when a user submits a form (in the browser) and he clicks the stop button before the process is terminated, the connection is closed automatically and a commit is done. I don't want a commit because my source code is doing several inserts in several tables and if the process is interrupted before all is done, I want a rollback otherwise the data will be corrupted.
Can I do it and Who ? Maybe overload the close() method ? How ?
Thank You,
mhuot
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Implement fa´┐Żade pattern - wrap all the method of Connection inside other class - say OraConnection with java.sql.Connection as its data member. Your application will make call to OraConnection which will have a method close(). close() will first rollback on Connection and the close the connection.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Not sure about this, why dont u try JTA. Using transactions u can put a bunch of JDBC code in a block. It is either execute all or execute none situation. I mean to say if there are three statements, 2 are executed and 1 fails to execute, then the other 2 gets rolledback automatically.
Regards,
Sim Sim.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why can't you just explicitly call conn.rollback() at every possible close point?
reply
    Bookmark Topic Watch Topic
  • New Topic