Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 67ED96328DF for ; Tue, 8 Jun 2010 13:12:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 87025-09 for ; Tue, 8 Jun 2010 16:12:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web110413.mail.gq1.yahoo.com (web110413.mail.gq1.yahoo.com [67.195.8.237]) by mail.postgresql.org (Postfix) with SMTP id 682B7632557 for ; Tue, 8 Jun 2010 13:12:33 -0300 (ADT) Received: (qmail 37155 invoked by uid 60001); 8 Jun 2010 16:12:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1276013551; bh=7X3Ajsit3Lfx9C9Ij8uEVI8Mz49jylmm1y9//+WHefg=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=JOHUMPBBAtfvFy5Zgg0CopvalFpgBFPmJMdSvjts4UBChLbYJM83mK/gMFHpP8rTCJfVs3005KMbRcHWTF3aV8idKQ7wM7ZnK80hNEL4KYaJIIYiuwt4/hOSkL94QLvuEWaS/d0gdtm07ny63wT/ARHqkDM1eGFOKrPRutyjx/I= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=KRoI4zPo2hfnySOtdru2rYYFK7NQZo7jHryNw3IHLuT5cYkl1sg0Cvey4mc7dYSsqANChbgnSkKwk5zXs5aJ+TF374D2jjWW49G3ugk7AjOAYOg6YwssCoTI0CbDdlf+Mct3lM6MSzU/91X+4d68e+t6ZRDDgqvqUxvpXQCXPG8=; Message-ID: <384952.35231.qm@web110413.mail.gq1.yahoo.com> X-YMail-OSG: 467wvzYVM1mc.MRD7ROD4EiHvlzEtmONXybELV2aWkHohHl URm70wYKSv6qurCAIT.bXemSXPujmPIuk0fMG0bwmoyNgBcXsSlbw9CfRJP7 ShOVm4vmmewl3.xIoMQkkXnAKW_CFeEjTOetphDFtK3hytKqs2XeA0d0wZuY GaG8mJZ029518tkxn_3xSDdF_HZ0QGDJnmc3JRrWcxIcIaYNFLDDNdpvnYYM pijhG.N.L81u2WIEu46KTQ99PRfhDgbYzvr0WFiEx4qhC3A7W5QLdylTh.2J R4KCFYcf7.UEo_rZszuEts7j8it7P2qrDJkIWyyfZnI1utfz4fqa5zQ-- Received: from [58.65.169.83] by web110413.mail.gq1.yahoo.com via HTTP; Tue, 08 Jun 2010 09:12:30 PDT X-Mailer: YahooMailRC/397.8 YahooMailWebService/0.8.103.269680 Date: Tue, 8 Jun 2010 09:12:30 -0700 (PDT) From: Altaf Malik Subject: IllegalArgumentException in batch execution To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-2098380411-1276013550=:35231" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.791 tagged_above=-10 required=5 tests=BAYES_50=0.8, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/48 X-Sequence-Number: 20618 --0-2098380411-1276013550=:35231 Content-Type: text/plain; charset=us-ascii All, I have noticed a strange behavior in jdbc. Consider the following code: /* CREATE TABLE public.testtbl ( a integer, b character varying(50)); */ Class.forName("org.postgresql.Driver"); Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres?loglevel=0","postgres","postgres"); PreparedStatement stmt = con.prepareStatement("insert into testtbl values(?,?)"); for (int i=0; i< 400;i++) { stmt.setInt(1, 110); if (i==0) stmt.setString(2, "Hello\0 Mr.X"); else stmt.setString(2, "Hello Mr.X"); stmt.addBatch(); } try{ stmt.executeBatch(); } catch(Exception exp){ stmt.clearBatch(); exp.printStackTrace(); } for (int i=0; i< 400;i++) { stmt.setInt(1, 10); stmt.setString(2, "Hello Mr.X"); stmt.addBatch(); } stmt.executeBatch(); When I execute this code, I get Two errors: (1): java.lang.IllegalArgumentException: org.postgresql.util.PSQLException: Zero bytes may not occur in string parameters. at org.postgresql.core.v3.SimpleParameterList.toString(SimpleParameterList.java:163) at org.postgresql.core.v3.SimpleQuery.toString(SimpleQuery.java:46) at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2586) at org.postgresql.core.v3.QueryExecutorImpl$ErrorTrackingResultHandler.handleError(QueryExecutorImpl.java:348) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1796) at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1055) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:398) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2727) at Main.main(Main.java:28) This error is fine because I am adding an invalid character. Here is 2nd error: (2) java.lang.IndexOutOfBoundsException: Index: 145, Size: 145 at java.util.ArrayList.RangeCheck(ArrayList.java:546) at java.util.ArrayList.get(ArrayList.java:321) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1680) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2727) at Main.main(Main.java:39) If I remove the first error, the second error is automatically removed. To me, it seems that this is some after effect of the first error. What is wrong here? Regards, Altaf Malik --0-2098380411-1276013550=:35231 Content-Type: text/html; charset=us-ascii
All,
 I have noticed a strange behavior in jdbc. Consider the following code:

/*
          CREATE TABLE public.testtbl (
            a  integer,
            b  character varying(50));
         */
        Class.forName("org.postgresql.Driver");
        Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres?loglevel=0","postgres","postgres");

        PreparedStatement stmt = con.prepareStatement("insert into testtbl values(?,?)");

        for (int i=0; i< 400;i++) {
            stmt.setInt(1, 110);
            if (i==0)
                stmt.setString(2, "Hello\0 Mr.X");
            else
                stmt.setString(2, "Hello Mr.X");
            stmt.addBatch();
        }

        try{
            stmt.executeBatch();
        } catch(Exception exp){
            stmt.clearBatch();
            exp.printStackTrace();
        }
       
        for (int i=0; i< 400;i++) {
            stmt.setInt(1, 10);
            stmt.setString(2, "Hello Mr.X");
            stmt.addBatch();
        }
        stmt.executeBatch();

When I execute this code, I get Two errors:

(1):
java.lang.IllegalArgumentException: org.postgresql.util.PSQLException: Zero bytes may not occur in string parameters.
        at org.postgresql.core.v3.SimpleParameterList.toString(SimpleParameterList.java:163)
        at org.postgresql.core.v3.SimpleQuery.toString(SimpleQuery.java:46)
        at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2586)
        at org.postgresql.core.v3.QueryExecutorImpl$ErrorTrackingResultHandler.handleError(QueryExecutorImpl.java:348)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1796)
        at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1055)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:398)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2727)
        at Main.main(Main.java:28)

This error is fine because I am adding an invalid character. Here is 2nd error:
(2)
java.lang.IndexOutOfBoundsException: Index: 145, Size: 145
        at java.util.ArrayList.RangeCheck(ArrayList.java:546)
        at java.util.ArrayList.get(ArrayList.java:321)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1680)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2727)
        at Main.main(Main.java:39)

If I remove the first error, the second error is automatically removed. To me, it seems that this is some after effect of the first error. What is wrong here?

Regards,
Altaf Malik

--0-2098380411-1276013550=:35231--