Reputation: 1
How transactions will behave; If I use following syntax to execute multiple DML using single java.sql.Statement
String sqlStr = "INSERT INTO.... \n update t1 set....";
statemet.execute(sqlStr);
I am not altering default connection setting (autocommit = true).
I am aware this is not the right way / best practice; just curious to know the transactional nature of above code That is if update fails with SQLException, will insert rollback?
Upvotes: 0
Views: 1877
Reputation: 11
I tried in MySQL environment. It worked very well. And I think it is the basic way to do so.
Upvotes: 0
Reputation: 3965
Tried out, got some surprising results with MS SQL sever 2008
I tried 2 update statements and as per observation they run in a single transaction; that is if second update fails first update statement is rolled back.
The surprising thing I noticed is :
Upvotes: 0
Reputation: 403451
With autocommit
set to true, then the individual statements would very likely execute in their own individual transactions. This might depends on the database, but I suspect not.
Best way to find out is to try it.
Upvotes: 1