aspose file tools*
The moose likes JDBC and the fly likes Transaction related question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Transaction related question" Watch "Transaction related question" New topic
Author

Transaction related question

Vicky Pandya
Ranch Hand

Joined: Dec 16, 2004
Posts: 148
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
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

Joined: Apr 14, 2004
Posts: 10336

Didn't Rob already ask that?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
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
 
subject: Transaction related question