Re: Is statement.executeBacth() a transaction?
- From: Martin Gregorie <martin@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Oct 2008 12:37:15 +0000 (UTC)
On Thu, 30 Oct 2008 21:22:54 -0700, George wrote:
Thank you. As always, I got a bit more confused on the other byIf you use the default (auto-commit) each SQL statement is treated as a
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.
separate commitment unit, IOW it does:
start commitment unit
execute SQL statement
if (statement failed)
rollback
else
commit
This is OK for most single-table updating, but as soon as you start to
work with multiple tables, e.g. storing a new payment detail, crediting
the recipient and debiting the sender, then you have several SQL
statements that must all complete successfully if the database is to be
consistent. Under these conditions you need to turn auto-commit off and
your program must explicitly commit or rollback depending on whether the
statement set completed or failed.
JDBC's batch execution has nothing to do with commitment apart from
telling you that all statements executed OK or that at least one failed.
This looks to me as if you'd need to disable auto-commit before using
batch execution, so you'd still need to commit or rollback. The javadoc
says that not all JDBC drivers support batch execution, so IMO if there's
any change that your code needs to run against different RDBMS then its a
good thing to avoid.
Batch execution isn't something I'd do myself. I prefer more control over
the transaction. In any case its only suitable for running an inline set
of SQL statements while many cases the update actions depend on the
database contents (e.g. do we update an existing row or must it be
inserted).
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
.
- References:
- Is statement.executeBacth() a transaction?
- From: George
- Re: Is statement.executeBacth() a transaction?
- From: Lew
- Re: Is statement.executeBacth() a transaction?
- From: George
- Re: Is statement.executeBacth() a transaction?
- From: Lew
- Re: Is statement.executeBacth() a transaction?
- From: George
- Is statement.executeBacth() a transaction?
- Prev by Date: Re: How to set the compiler to handle thousand loops ?
- Next by Date: Re: Redundant GPS data
- Previous by thread: Re: Is statement.executeBacth() a transaction?
- Next by thread: Re: Is statement.executeBacth() a transaction?
- Index(es):
Relevant Pages
|