pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedincomplete batch-updates
2+ messages / 2 participants
[nested] [flat]
* incomplete batch-updates
@ 2007-07-11 13:17 Marcel Steinbach <steinbach@gmx.com>
0 siblings, 1 reply; 2+ messages in thread
From: Marcel Steinbach @ 2007-07-11 13:17 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
i'm having trouble with batches. When I run into an BatchUpdateException,
the table is filled up to a multiple of 256 records (guess, the batch seems to be executed in 256-steps), and, for example, if the Exception was thrown at the 300. statements, the tablesize is 256, and 44 are missing - but: The getUpdateCount() says, that all statements until the Exception (299) affacted "1" row.
My code looks something like this:
---------------------------------------------------------
PreparedStatement stmt = con.prepareStatement(sql);
con.setAutoCommit(true);
for (int i = 0; i < objectBuffer.length; i++) {
for (int j =0; j < objectBuffer[i].length; j++) {
stmt.setObject(j+1, objectBuffer[i][j]);
}
stmt.addBatch();
}
int updateCount[] = { };
try {
updateCount = stmt.executeBatch();
} catch (...) { ...
---------------------------------------------------------
Some ideas whats wrong? I'm using postgresql-8.1-405.jdbc3.
Best Regards
Marcel Steinbach
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: incomplete batch-updates
@ 2007-07-15 15:42 Kris Jurka <books@ejurka.com>
parent: Marcel Steinbach <steinbach@gmx.com>
0 siblings, 0 replies; 2+ messages in thread
From: Kris Jurka @ 2007-07-15 15:42 UTC (permalink / raw)
To: Marcel Steinbach <steinbach@gmx.com>; +Cc: pgsql-jdbc
On Wed, 11 Jul 2007, Marcel Steinbach wrote:
> i'm having trouble with batches. When I run into an
> BatchUpdateException, the table is filled up to a multiple of 256
> records (guess, the batch seems to be executed in 256-steps), and, for
> example, if the Exception was thrown at the 300. statements, the
> tablesize is 256, and 44 are missing - but: The getUpdateCount() says,
> that all statements until the Exception (299) affacted "1" row.
>
While you have setAutoCommit true, the server is still running a
transaction around the JDBC driver's internal batch size of 256. So
the driver sends the first 256 statements and they go through fine
and get committed. Then it sends the next 44 and finds an error and rolls
it back. So if you really want each statement to be in its own
transaction you shouldn't use batch execution. There will be no
performance gain from using batch execution unless the server/driver can
actually batch something together.
Kris Jurka
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-07-15 15:42 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-07-11 13:17 incomplete batch-updates Marcel Steinbach <steinbach@gmx.com>
2007-07-15 15:42 ` Kris Jurka <books@ejurka.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox