• 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

Using transaction processing (commit())

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a BEGIN TRANSACTION statement in Java? How does Java know when a transaction begins? I have code that updates a number of database tables and either they all succeed or they all need to be rolled back. I have a try block with a number of SQL statements then a commit() at the end of the try. Then I have a catch with the rollback() statement. The rollback does not appear to be working. I did set the autoCommit to false at the beginning of the program.
 
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
sounds like you did it correctly:
setAutoCommit( false );
..execute a bunch of DML statements
if successful ( commit() )
else rollback()
that's it. If you are having troubles, maybe your database/driver does not support transactions ( like MS Access ). If you are using a database/driver combo that supports transactions, post some code and maybe we can help.
Jamie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic