Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction related question

 
Vicky Pandya
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

could be a stupid question:- I have a requirement that part of the same transaction, I need to insert and subsequently make two more updates to the same records (same pk) in a single transaction. These operations have to be all or nothing. Anyway to achieve in a single transaction? or any other idea?

Thanks,
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe this is database related, so I'll move this to our JDBC forum.

For transactions in JDBC you can use a combination of Connection.setAutoCommit(false) to disable automatic committing of separate statements, Connection.commit() to finish a transaction and Connection.rollback() to undo everything after the last commit.

I don't get one thing though. Why can't you set these values for the newly inserted record when you insert it?
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have to update the record twice in the same transaction? Cant you use the last value directly and commit the transaction?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't Rob already ask that?
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Didn't Rob already ask that?


Yes, he has. But I didnt actually take a good look at his post.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic