This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

how to find the connection object is commitable  RSS feed

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i done connection.setAutoCommit(false) and done some operation in my connection like select some columns and update some table after all this operations i like to know weather my connection object is commitable, ie i want to know weather i need to execute connection.commit() or connection.rollback()

thanks
 
author & internet detective
Posts: 39084
714
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Baiju,
Whether to commit or rollback is usually a business decision. If a call threw a SQLException, you would almost certaintly want to rollback. But that would have been handled by autocommit and a transaction. Think back to why you set autocommit to false. What problem were you trying to solve?
 
Baiju Varugese
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jeanne,
Thank you. I want to do a two-phase commit for a connection, (it is already provided by JTA, reinvent the wheel). I want to write a connection manager that handles N number of connection in a transaction. i want to know all the statements in all the connection object is executed fine then i want to fire the commit on all the connection object or else i want to fire rollback. if there is any exception raised at the time of commiting i want to do the rollback on all the other connection.

thanks
 
Jeanne Boyarsky
author & internet detective
Posts: 39084
714
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Baiju,
You could write a wrapper around the connection to track whether it should rollback. This object could run all queries on the user's behalf and therefore tell whether an exception occurred. Or provide a setRollbackOnly() method for callers to do this explicitly.
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!