Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bxA7Z-0002xr-8z for pgsql-jdbc@arkaria.postgresql.org; Thu, 20 Oct 2016 09:58:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bxA7Y-0003iP-Ld for pgsql-jdbc@arkaria.postgresql.org; Thu, 20 Oct 2016 09:58:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bxA73-00033l-IG for pgsql-jdbc@postgresql.org; Thu, 20 Oct 2016 09:58:14 +0000 Received: from nm5-vm4.bullet.mail.ir2.yahoo.com ([212.82.96.111]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bxA6z-00031X-5H for pgsql-jdbc@postgresql.org; Thu, 20 Oct 2016 09:58:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1476957486; bh=ezKCvdFkfsh9I+pa1imt2tiLb1KKenxtsdjnEvQoyns=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=ZfkoVyQP/ZHDiiTG0eus8NXqdS74d8na4j9OF8h11X8HCuaZkpEv/FHg80jLMOMjFYmkYNOfaYpYipm8mB5ydJ5VP1L9FkZDnsGlNwOlM+oWR4vxSZzdBo4WbsZRxbt0q50DXDtj4R8tERW6gikVFkKtBYVRbbkRNNiUkCrfKStjuOU08ER55PxuVBTEf81OUuQ41ieLwJgMdMKaG7eTRmffs5T6Pp7cRysYDO8wdRrNQlX2wnDqGCENpz/F4rTpeEdy5gU0wO+oFwjdVJ+AalCTp/pKilGp4TJxW4JYYOcijJPyuueQ4PURAlMntozxo2biaoaNYf1tfn/MX9WHyw== Received: from [212.82.98.124] by nm5.bullet.mail.ir2.yahoo.com with NNFMP; 20 Oct 2016 09:58:06 -0000 Received: from [212.82.98.91] by tm17.bullet.mail.ir2.yahoo.com with NNFMP; 20 Oct 2016 09:58:06 -0000 Received: from [127.0.0.1] by omp1028.mail.ir2.yahoo.com with NNFMP; 20 Oct 2016 09:58:06 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 956511.79932.bm@omp1028.mail.ir2.yahoo.com X-YMail-OSG: qtxQH.QVM1nqBFfabJ8Z.QplxKmoOORZTuN6EmH.1jkEnerScP1FsrnfC0v1ECf rad..F.P5FyCLGEfQwnAt5akk0KJv8YFhF8qSkiJ7IWROcvl.Ny16MXKo6DkaaM2P1bGRfWjDsS8 YR8g3a1N5DzJ6NQpWyv2OYeaqFwKdFZxFz7uXbTTJYaa0.xi9RXLN10g2RfYGub5pWU4X.vyRl1a K63iQqrj3ZNcncFydqgiW9.m3pWqQa7Ow4VT7PHLfizbO0Zfzw79UwCtyM1Ze5EpVOs6sMrltYs6 XjBgbzblzM_wMUKIMbtTARjM7HEKOos9GavKX1NfRRw7Bg8DLmH_tWZgU17OUib4HjnJMa_pw1A_ A9gnWAN2cFiOalTjqfEdzOOzqXgIVOzr20IMs0SN3gYLqXvYKYFEdEvjlkG71WMgSWnFh0EhEAZb sSigzmPvhadGFvNg6jwj5m4.27CqYF4oXjnOfhjvmwM.ltg.TEyBAuwlOq3fcDuLhwyRPDXDsOXd ogrLm3j.smJv04FYCPkxTipWrpSRkO6G2nYwSZ5x8s_lVVY17VhweiBldDc4hx7kI5w-- Received: from jws700014.mail.ir2.yahoo.com by sendmailws103.mail.ir2.yahoo.com; Thu, 20 Oct 2016 09:58:06 +0000; 1476957486.571 Date: Thu, 20 Oct 2016 09:56:31 +0000 (UTC) From: Tillmann Schulz Reply-To: Tillmann Schulz To: Jeremy Whiting , "pgsql-jdbc@postgresql.org" Message-ID: <128893136.457015.1476957391382@mail.yahoo.com> In-Reply-To: <2138ea64-c48f-c081-960b-f20ddcc53a93@redhat.com> References: <65622026.6539291.1476877760626.ref@mail.yahoo.com> <65622026.6539291.1476877760626@mail.yahoo.com> <2138ea64-c48f-c081-960b-f20ddcc53a93@redhat.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: quoted-printable Content-Length: 5959 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 your response. Meanwhile I found the issue, that causes my problem: https://github.com/pgjdbc/pgjdbc/issues/502 So the question is "if the driver should mark all the rows in int[] execute= Batch() with Statement.EXECUTE_FAILED" when a single statement fails. Other drivers like oracle-jdbc work the same way like postgres does before = issue #502 was released. The fix would be to remove the code of issue #502 from the driver. As next step for me I will create an issue on github. Bye Tillmann ----- Urspr=C3=BCngliche Message ----- Von: Jeremy Whiting An: Tillmann Schulz ; "pgsql-jdbc@postgresql.org" Gesendet: 11:18 Donnerstag, 20.Oktober 2016 Betreff: Re: [JDBC] Return Codes of BatchUpdateException in PostgreSql 9.6 Hi Tillmann, Thank you for providing the test case. I suggest you take a look at=20 this class [1] in the testsuite. It may answer your question on what to=20 expect in updateCount. If you question is not answered and the tests in that class do not=20 exercise what is provided in your test case then I suggest the following: a) Create an issue [2] on Github. b) Fork the pgjdbc project. c) Add your contributed test into [1] as a new test method. Even better=20 is to include a fix along with the test case. d) Create a Pull Request (PR) to have your test merged into master. Also=20 update your created issue with details of the PR. So the two are linked. This way the project can ensure this problem you are seeing does not=20 reoccur again in the future. If it is indeed a defect. Regards, Jeremy [1]=20 https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/test/java/org/postg= resql/test/jdbc2/BatchExecuteTest.java [2] https://github.com/pgjdbc/pgjdbc/issues On 19/10/16 12:49, Tillmann Schulz wrote: > Hi, > > thanks for the response. > > > > I have a simple test program which first creates a testtable, fills it wi= th 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, ClassNotFou= ndException, IOException > { > /////////////////////////////////////////////////////////////////////////= ///////////// > // CHANGE THIS > String dbUrl =3D "jdbc:postgresql://localhost:5432/db?charSet=3DUTF-8"; > String dbUser =3D "user"; > String dbPassword =3D "xxxx"; > /////////////////////////////////////////////////////////////////////////= ///////////// > > try > { > Connection con =3D openConnection( dbUrl, dbUser, dbPassword ); > con.setAutoCommit( false ); > > try > { > // Prepare Table > Statement stmtDrop =3D con.createStatement(); > stmtDrop.execute( "DROP TABLE IF EXISTS TESTTABLE " ); > con.commit(); > Statement stmtCreate =3D con.createStatement(); > stmtCreate.execute( "CREATE TABLE TESTTABLE (id INTEGER PRIMARY KEY)" ); > con.commit(); > Statement stmtData =3D 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 =3D openConnection( dbUrl, dbUser, dbPassword ); > con.setAutoCommit( false ); > > Statement stmt =3D con.createStatement(); > for( int i =3D 0; i < 10; i++ ) > { > stmt.addBatch( "INSERT INTO TESTTABLE VALUES('" + i + "')" ); > } > > stmt.executeBatch(); > > con.commit(); > } > catch( java.sql.BatchUpdateException x ) > { > final int[] updateCounts =3D x.getUpdateCounts(); > for( int i =3D 0; i < updateCounts.length; i++ ) > { > System.err.println( "updateCounts[" + i + "]=3D" + updateCounts[i] ); > } > // First 5 statements are successfully, so update count should be 1 > for( int i =3D 0; i < 5; i++ ) > { > if( updateCounts[i] !=3D 1 ) > System.err.println( "Wrong information returned = by driver for update Count " + i ); > } > // 5th statement > if( updateCounts[5] =3D=3D -3 ) > System.err.println( "Correct information returned by= driver for update Count " + 5 ); > > } > } > catch( SQLException s ) > { > > s.printStackTrace(); > > if( s.getNextException() !=3D 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 =3D new Properties(); > // Activate for logging > // props.setProperty( "loglevel", "2" ); > // FileWriter fw =3D new FileWriter( "C:\\temp\\test12345.txt" ); > // DriverManager.setLogWriter( new PrintWriter( fw ) ); > > props.setProperty( "user", user ); > props.setProperty( "password", password ); > return DriverManager.getConnection( url, props ); > > } > > } > > --=20 Jeremy Whiting Senior Software Engineer, Middleware Performance Team JBoss, by Red Hat ------------------------------------------------------------ Registered Address: RED HAT UK LIMITED, Peninsular House, 30-36 Monument St= reet, 4th floor, London. EC3R 8NB United Kingdom Registered in UK and Wales under Company Registration No. 3798903 Director= s: Michael Cunningham (US), Michael ("Mike") O'Neill (Ireland) and Eric Sha= nder (US) --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc