Re: Is statement.executeBacth() a transaction?



Thank you. As always, I got a bit more confused on the other by
clearing up one part. I originally thought all the statements in one
transaction are all executed or non executed in jdbc automatically. Am
I right? However, the second last paragraph in the article I linked
seems to say the opposite. It says one needs to rollback when
SQLExcption is thrown, which seems to indicate that one transaction
(one conn.commit()) might leave some statement executed and some
not.

On Oct 30, 7:48 pm, Lew <no...@xxxxxxxxxxxxx> wrote:
George wrote:
 "Transaction" for me is just either all statements executes or none
run.  I got the impression about the preparedstatement#addbatch() as a
transaction from sun's document here
http://java.sun.com/docs/books/tutorial/jdbc/basics/transactions.html.
They pointed out that rollback is not necessary in their example
program toward the end.  So I figure that is executed as one
transaction.

That example makes no mention whatsoever of executeBatch().  The reason they
say rollback isn't necessary is because no further use is made of the data
after a SQLException.  The tutorial even goes on to say:

If the application continued and used the results of the transaction,
however, it would be necessary to include a call to rollback in the
catch block in order to protect against using possibly incorrect data.

The paired statements in their example are, in fact, executed as a single
transaction, but that is not why rollback isn't needed.

--
Lew

.



Relevant Pages

  • Re: Is statement.executeBacth() a transaction?
    ... transaction from sun's document here ... That example makes no mention whatsoever of executeBatch(). ... The reason they say rollback isn't necessary is because no further use is made of the data after a SQLException. ... it would be necessary to include a call to rollback in the catch block in order to protect against using possibly incorrect data. ...
    (comp.lang.java.programmer)
  • Is statement.executeBacth() a transaction?
    ... transaction and I do not need a rollback. ... How about executeBatch() in ... Statement deleteState = conn.createStatement; ... for (String table: tableNames) { ...
    (comp.lang.java.programmer)
  • Re: Classic Nest SP with Transaction Question
    ... enclosing transaction or should begin and commit/rollback its own ... > I echo Ron's points and also have been using an approach very similar to> Tom's method of using a SAVE PT instead of starting a new TRANSACTION if the> ChildSP is called from the ParentSP. ... > The ParentSp now has to ROLLBACK everything up to that point. ... As Ron> mentioned, the ParentSP may have called many child SPs, and performed many> updates up to this point, and all of these need to be rolled back. ...
    (microsoft.public.sqlserver.programming)
  • 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: Classic Nest SP with Transaction Question
    ... This will take care of what is done in the child, but what I want to do is ... rollback the entire outer transaction - the one initiated in the outer SP. ...
    (microsoft.public.sqlserver.programming)