Thanks for the question, rit.
Asked: December 10, 2015 - 8:34 pm UTC
Last updated: December 11, 2015 - 4:38 pm UTC
Version: 12c
Viewed 1000+ times
You Asked
I am using Oracle with AutoCommit ON mode (Java Application using JDBC).
When I execute multiple DML statements as a single transaction, I thought I could do something like this:
set transaction read write
update user_tbl set name='mark' where email='m@xyz.com'
update user_tbl set name='ken' where email='k@xyz.com'
--if other things are successful, then:
commit
-- else:
--rollback
But when I do end up executing "rollback", the rows still keep New values given my above statements.
Is it possible that update statements are being executed in AutoCommit ON mode ? and did the "set transaction" not start a transaction for me?
and Chris said...
In Oracle a transaction ends when you commit or rollback your work.
Setting autocommit on in JDBC issues an implicit commit after every statement. So each of your update statements are in their own transaction. To prevent this, you need to set autocommit off
For further details, see:
https://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html
Rating
(1 rating)
Is this answer out of date? If it is, please let us know via a Comment