• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting started with transactions

 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've searched but can't find a good tutorial on using database transactions. I'm working on an app that needs to update or insert records in two different tables so I want to wrap them into one atomic transaction, but I'm not sure how to get started.

Can someone point me to a good resource for learning this technique?

TIA
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already know well what database transaction is and what is it for, and just need to know how to use that from Java, you can read the JDBC tutorial. The transaction related stuff is here, but you might be interesting in reading the whole JDBC tutorial.

If you're interested into transactions as such and the information on transactions in the JDBC tutorial is not sufficient to you, I'd suggest googling up SQL tutorial or database transactions. I don't know any specific tutorial on this subject I could offer.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, I'm not using any frameworks. I've been digging through the Oracle docs and finally found something that isn't geared toward using EJB's here.

If I understand correctly (doubtful) it consists of more or less doing the following:

1. Turn off auto-commit.
2. Setup and run the prepared statements.
3. Run commit on the connection.
4. If an exception is throw, do a rollback.
5. Turn on auto-commit.

Is that more or less the gist of it?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is right. You might save the original autocommit state and restore it when finished, though.

In my application I don't bother restoring autocommit state. I never ever want to use autocommit, so I leave it off. Don't do this if you are not 100% sure there is no code that would require autocommit, though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic