Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjYTt-0004f9-7q for pgsql-jdbc@arkaria.postgresql.org; Fri, 14 Dec 2012 16:51:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TjYTs-0004nB-8d for pgsql-jdbc@arkaria.postgresql.org; Fri, 14 Dec 2012 16:51:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjYTr-0004mF-1m for pgsql-jdbc@postgresql.org; Fri, 14 Dec 2012 16:51:23 +0000 Received: from mail63.csoft.net ([205.205.214.4]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjYTk-0000lt-Eb for pgsql-jdbc@postgresql.org; Fri, 14 Dec 2012 16:51:22 +0000 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail63.csoft.net (Postfix) with ESMTP id 5669F2848E; Fri, 14 Dec 2012 11:51:14 -0500 (EST) Received: by leary.csoft.net (Postfix, from userid 1112) id 4F2DA1FBC8; Fri, 14 Dec 2012 11:51:14 -0500 (EST) Date: Fri, 14 Dec 2012 11:51:14 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Haifeng Liu cc: dmp , pgsql-jdbc@postgresql.org Subject: Re: Fwd: [ADMIN] Confuse about the behaveior of PreparedStatement.executeBatch (jdbc) In-Reply-To: Message-ID: References: <50CB4C40.7000104@ttc-cmc.net> User-Agent: Alpine 2.00 (BSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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 -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc