Re: Is statement.executeBacth() a transaction?



George <zggame@xxxxxxxxx> wrote in news:d921316c-2deb-4de2-9db8-
c7240f538fde@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:

Well. English is not my native tongue. So maybe I did miss some
point and did not make my question clearer enough. My question is what
happened when a commit() call failed and SQLException throwed? In the
example, let us assume that after conn.commit(), driver is able to
make the first update (XXXX), but fails on the second (YYYY). Will
the jdbc driver automatically roll the database back to the situation
before update XXXX or leave the database in the situation that XXXX
updated and yyyy not? In the first case, I do not need to put the
rollback() in the catch since the driver already does that, but in the
second case, I need to take care of it myself by calling rollback
explicitly.

The reason I am confused about it is that the "transaction" nature
indicates the all or nothing approach. But I am not sure whether this
is part of the jdbc driver's responsibility or mine?

try{
conn.setAutoCommit(false);
Statement state1=conn.createStatement();
state1.addBatch("update XXXX");
state1.addBatch("update YYYY");
state1.executeBatch();
conn.commit();
}

catch( SQLException e){
if (conn!=null)
try{ conn.rollback();}
catch(SQLException e){
}

}


addBatch is not more powerful than any execute or such statement. If you
get a rollback, everything that was done after the setAutoCommit(false)
will be rolled back.

addBatch or executeBatch will not make any "partial" transactions inside
your actual transaction.

A commit is a commit, a rollback is a rollback. It's that easy.

.



Relevant Pages

  • Re: Classic Nest SP with Transaction Question
    ... PMFJI, but if your child proc is using an explicit tran, then it can be coded as follows: create proc dbo.ChildProc as set nocount on declare @trancount int set @trancount = @@TRANCOUNT if @trancount> 0 begin tran ChildProcTran else save tran ChildProcTran /* ... Do some stuff */ if @@ERROR> 0 begin raiserror rollback ChildProcTran return end ... commit tran go ... I believe I'm having the same issue as Chad with nested stored procedures inside a transaction. ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL SERVER Rollback Problems
    ... It will not be fully committed until you issue a COMMIT TRAN. ... If your sp had an error or was manually stopped the transaction is still ... issue the ROLLBACK ALL operations are rolled back up until that first BEGIN ... > execution. ...
    (microsoft.public.sqlserver.programming)
  • Re: how to roll back
    ... You can only use rollback within a transaction block. ... If you commit a ... COMMIT TRAN, then ROLLBACK TRAN to ...
    (microsoft.public.sqlserver.server)
  • Re: help - transaction control
    ... transaction to successfully commit before any of the inner ones are ... If a Rollback is issued anywhere along the way ALL transactions ... ROLLBACK TRAN ... > My understanding of the way that transactions nest> is that I should be able to have each SP> begin and commit a transaction within itself,> and if the SP happens to be called from some context> that has begun a transaction, then the SP would participate> in that transaction context. ...
    (microsoft.public.sqlserver.programming)
  • Re: transaction demarction
    ... do they mark something? ... a banking transaction that moves money from one bank account ... that involves database access and ends when you either COMMIT or ROLLBACK. ...
    (comp.lang.java.programmer)