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

From: dmp <danap(at)ttc-cmc(dot)net>
To: Haifeng Liu <liuhaifeng(at)live(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Date: 2012-12-14 15:56:48
Message-ID: 50CB4C40.7000104@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general pgsql-jdbc

Hello,

Though a simple example of your code would provide a better response
from the mailing list, I will speculate based on the context of the
Java 6 API, statement class and your comments. Yes, the batch appears
to be proceeding.

Statement.executeBatch().

executeBatch

int[] executeBatch() throws SQLException
~
~
~
If one of the commands in a batch update fails to execute properly,
this method throws a BatchUpdateException, and a JDBC driver may or may not
continue to process the remaining commands in the batch. However, the driver's
behavior must be consistent with a particular DBMS, either always continuing to
process commands or never continuing to process commands. If the driver
continues processing after a failure, the array returned by the method
BatchUpdateException.getUpdateCounts will contain as many elements as there are
commands in the batch, and at least one of the elements will be the following:
~
~
~
Returns:
an array of update counts containing one element for each command in
the batch. The elements of the array are ordered according to the order in which
commands were added to the batch.

Throws:
SQLException - if a database access error occurs, this method is called on
a closed Statement or the driver does not support batch statements. Throws
BatchUpdateException (a subclass of SQLException) if one of the commands sent to
the database fails to execute properly or attempts to return a result set.

You may be able to answer your own question by examining the int[] array that
is returned by way of BatchUpdateException.getUpdateCounts()

danap.

Haifeng Liu wrote:
>> Hi,
>>
>> I have a DB writer program written in Java, it do batch updates, and
>> will try to update each record in a batch if it failed. I think no any
>> record in a batch will be update if the batch failed, but weirdly I
>> found a few records update twice(very little amount among all records).
>>
>> Well, there is less stuff about postgresql jdbc driver. I wanna know
>> if executeBatch really keep all the records in a batch untouched when
>> the batch failed. Any help is appreciate.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Maciek Sakrejda 2012-12-14 16:05:00 Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Previous Message Greg Williamson 2012-12-14 03:34:34 Re: allow a user to see current_query in pg_stat_activity in 8.4

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2012-12-14 16:00:50 Re: Implicit casts to array types
Previous Message joshua 2012-12-14 15:52:30 Re: Implicit casts to array types

Browse pgsql-jdbc by date

  From Date Subject
Next Message Maciek Sakrejda 2012-12-14 16:05:00 Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc)
Previous Message Chen Huajun 2012-12-14 13:29:33 Re: performance problem of Failover Datasource?