pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
IllegalArgumentException in batch execution
2+ messages / 2 participants
[nested] [flat]

* IllegalArgumentException in batch execution
@ 2010-06-08 16:12 Altaf Malik <mmalik_altaf@yahoo.com>
  2010-06-09 06:10 ` Re: IllegalArgumentException in batch execution Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Altaf Malik @ 2010-06-08 16:12 UTC (permalink / raw)
  To: pgsql-jdbc

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



      

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: IllegalArgumentException in batch execution
  2010-06-08 16:12 IllegalArgumentException in batch execution Altaf Malik <mmalik_altaf@yahoo.com>
@ 2010-06-09 06:10 ` Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Kris Jurka @ 2010-06-09 06:10 UTC (permalink / raw)
  To: Altaf Malik <mmalik_altaf@yahoo.com>; +Cc: pgsql-jdbc



On Tue, 8 Jun 2010, Altaf Malik wrote:

> All,
>  I have noticed a strange behavior in jdbc. Consider the following code:
> 
>         PreparedStatement stmt = con.prepareStatement("insert into testtbl
> values(?,?)");
> 
>             stmt.setInt(1, 110);
>             stmt.setString(2, "Hello\0 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.

This has been fixed in CVS.

Kris Jurka


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2010-06-09 06:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-06-08 16:12 IllegalArgumentException in batch execution Altaf Malik <mmalik_altaf@yahoo.com>
2010-06-09 06:10 ` Kris Jurka <books@ejurka.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox