Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc) - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Date
Msg-id alpine.BSO.2.00.1212141147030.30031@leary.csoft.net
Whole thread Raw
In response to Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)  (Haifeng Liu <liuhaifeng@live.com>)
List pgsql-jdbc

On Sat, 15 Dec 2012, Haifeng Liu wrote:

> I did a simple test and found that if one of the batch failed, the other
> update may be execute partially. when I test with 10 updates a batch,
> none of them are updated, when I test with 1000 updates a batch, about
> 700+ of them are executed, but the failed update should be the last one,
> which means 999 executed updates is more reasonable than 700+. But
> really weird thing is the getUpdateCounts method returns the reasonable
> information.
>
> I don't know what happened inside this driver. Currently I have to
> setAutoCommit to false and use commit/rollback to achieve my goal.
>

Internally the driver splits each batch into sub-batches of 250 to send to
the server to reduce the possibility of deadlocking the network
connection.  When auto-commit is enabled in the driver, the auto-commit
setting affects the whole sub-batch of 250 because of how the
frontend/backend protocol works.  So you are seeing some oddities because
of some implementation details and you should not use auto-commit with
batch statements.

Kris Jurka


pgsql-jdbc by date:

Previous
From: dmp
Date:
Subject: Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Next
From: dmp
Date:
Subject: Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)