Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bwpO0-0000SS-JL for pgsql-jdbc@arkaria.postgresql.org; Wed, 19 Oct 2016 11:50:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bwpO0-0000f8-4P for pgsql-jdbc@arkaria.postgresql.org; Wed, 19 Oct 2016 11:50:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bwpNT-0007nu-HW for pgsql-jdbc@postgresql.org; Wed, 19 Oct 2016 11:49:48 +0000 Received: from nm5-vm9.bullet.mail.ir2.yahoo.com ([212.82.96.116]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bwpNQ-0006ar-LB for pgsql-jdbc@postgresql.org; Wed, 19 Oct 2016 11:49:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1476877782; bh=zZvHpV9nqWLCdI3rv05ieChGWmfSf35LmqAVutitZx0=; h=Date:From:Reply-To:To:Subject:References:From:Subject; b=Ee1eX97Yvf38FnJmQU0wd/2nnOn2qECYpH8xiL4yCY4JthyRxm0z2HxVJI9/lbInsQI0YY42yWjbIa8Z3Wm20akwzSrbv5I06uCJKXq9mxDro5dzzGC8epmgZIpC8TRtj58v6TN3lDPu/HwpfO/xKN38pm16zUxY2zIAF4lLlb20dN8aaxRuC4pteXppgOMeljRmVlYjCbZR+t7+nFAg+TsbJ5W4b9dSDaUWAfxmiPCojCO+vcugAJu0+dCCk+TA6CQERdBIDXnqsBYTk6f3g2SQhxFDnR9UPerWujXoasg1OrnIoCiHmHlIie1dsh3QP6KY6an/HblIhwbdh+/oJw== Received: from [212.82.98.52] by nm5.bullet.mail.ir2.yahoo.com with NNFMP; 19 Oct 2016 11:49:42 -0000 Received: from [212.82.98.72] by tm5.bullet.mail.ir2.yahoo.com with NNFMP; 19 Oct 2016 11:49:42 -0000 Received: from [127.0.0.1] by omp1009.mail.ir2.yahoo.com with NNFMP; 19 Oct 2016 11:49:42 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 118437.98985.bm@omp1009.mail.ir2.yahoo.com X-YMail-OSG: FBfEwNgVM1kxU9vwIyCfzgaelE9Ilh6gPvJPjdUbK5cSSc8MFcE8FC6JW9ynxL1 KL1y72PlJ9uP1KThuAtUlkwd8QiJ3mlBqQIOOtySpN5L3zDKUxoIGsQUIedHbvBzv0z_q1IBH9f6 vYL0xJ7ipPo_rZwaEfWrzqmB2JQLteAUWTsQJ0egB0dEA3jcf6eC.uAQuCbDRQr8Q8mcbJ5pGNzg b11Dsw.T5.B1CP.m8DMVnbP.mFJIpkqNpssbhZIR0XXm4A0dPp52PO4Y14Ij2c1ae6VHJrrx9R6f ghxYO4sVzDd2HMVrNGIcI7K8gRNXtx8LuL6FYwlJrDc7tgoZKYMlFPvNV6FupDnOqno3W5fPJa9p .VMWSutkVjPRk1VcT.bhKbGskhOwOM_gdys5LIx6a_mZLW0cZYLAAvW88UsYlEuNOuxkhYcNFZQJ mWGkfsAM2cxL7eldz1ypfSdqp8ymzgVvjYyzuJKPP2weSIDysc7U4wW2jhlfKApfyljDh.iuDPTB T0uFhqY8kYf2TMcTsQxtR4LD7 Received: from jws700019.mail.ir2.yahoo.com by sendmailws102.mail.ir2.yahoo.com; Wed, 19 Oct 2016 11:49:41 +0000; 1476877781.722 Date: Wed, 19 Oct 2016 11:49:20 +0000 (UTC) From: Tillmann Schulz Reply-To: Tillmann Schulz To: "pgsql-jdbc@postgresql.org" Message-ID: <65622026.6539291.1476877760626@mail.yahoo.com> Subject: Re: Return Codes of BatchUpdateException in PostgreSql 9.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit References: <65622026.6539291.1476877760626.ref@mail.yahoo.com> Content-Length: 3347 X-Pg-Spam-Score: -1.5 (-) 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 Hi, thanks for the response. I have a simple test program which first creates a testtable, fills it with one record and does a batch insert of 10 records. The 5th insert causes a BatchUpdateException at stmt.executeBatch() when the data is NOT commited. The question is, which return codes should be in x.getUpdateCounts(). For better reading I placed the test programm on http://pastebin.com/0P1S6zEc Bye, Tillmann import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class TestUpdateCount { public static void main( String[] args ) throws SQLException, ClassNotFoundException, IOException { ////////////////////////////////////////////////////////////////////////////////////// // CHANGE THIS String dbUrl = "jdbc:postgresql://localhost:5432/db?charSet=UTF-8"; String dbUser = "user"; String dbPassword = "xxxx"; ////////////////////////////////////////////////////////////////////////////////////// try { Connection con = openConnection( dbUrl, dbUser, dbPassword ); con.setAutoCommit( false ); try { // Prepare Table Statement stmtDrop = con.createStatement(); stmtDrop.execute( "DROP TABLE IF EXISTS TESTTABLE " ); con.commit(); Statement stmtCreate = con.createStatement(); stmtCreate.execute( "CREATE TABLE TESTTABLE (id INTEGER PRIMARY KEY)" ); con.commit(); Statement stmtData = con.createStatement(); stmtData.execute( "INSERT INTO TESTTABLE VALUES (5)" ); con.commit(); // TestCase: Insert 10 statements via jdbc batch. // 5h statement should fail because of duplicate key error con = openConnection( dbUrl, dbUser, dbPassword ); con.setAutoCommit( false ); Statement stmt = con.createStatement(); for( int i = 0; i < 10; i++ ) { stmt.addBatch( "INSERT INTO TESTTABLE VALUES('" + i + "')" ); } stmt.executeBatch(); con.commit(); } catch( java.sql.BatchUpdateException x ) { final int[] updateCounts = x.getUpdateCounts(); for( int i = 0; i < updateCounts.length; i++ ) { System.err.println( "updateCounts[" + i + "]=" + updateCounts[i] ); } // First 5 statements are successfully, so update count should be 1 for( int i = 0; i < 5; i++ ) { if( updateCounts[i] != 1 ) System.err.println( "Wrong information returned by driver for update Count " + i ); } // 5th statement if( updateCounts[5] == -3 ) System.err.println( "Correct information returned by driver for update Count " + 5 ); } } catch( SQLException s ) { s.printStackTrace(); if( s.getNextException() != null ) { s.getNextException().printStackTrace(); } } catch( Exception s ) { s.printStackTrace(); } } private static Connection openConnection( String url, String user, String password ) throws ClassNotFoundException, SQLException, IOException { try { Class.forName( "org.postgresql.Driver" ); } catch( ClassNotFoundException e ) { System.err.println( "Could not load driver!" ); throw e; } Properties props = new Properties(); // Activate for logging // props.setProperty( "loglevel", "2" ); // FileWriter fw = new FileWriter( "C:\\temp\\test12345.txt" ); // DriverManager.setLogWriter( new PrintWriter( fw ) ); props.setProperty( "user", user ); props.setProperty( "password", password ); return DriverManager.getConnection( url, props ); } } -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc