Re: Is statement.executeBacth() a transaction?
- From: Donkey Hottie <spam@xxxxxxxxxxxxxxxxx>
- Date: 01 Nov 2008 00:30:44 GMT
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.
.
- Follow-Ups:
- Re: Is statement.executeBacth() a transaction?
- From: George
- Re: Is statement.executeBacth() a transaction?
- References:
- Re: Is statement.executeBacth() a transaction?
- From: George
- Re: Is statement.executeBacth() a transaction?
- Prev by Date: Re: Create Mailbox with java language
- Next by Date: Re: Tomcat/Servlet Generic Error Handler
- Previous by thread: Re: Is statement.executeBacth() a transaction?
- Next by thread: Re: Is statement.executeBacth() a transaction?
- Index(es):
Relevant Pages
|