From: Altaf Malik <mmalik_altaf@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: IllegalArgumentException in batch execution
Date: Tue, 8 Jun 2010 09:12:30 -0700 (PDT)
Message-ID: <384952.35231.qm@web110413.mail.gq1.yahoo.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mmalik_altaf@yahoo.com
Subject: Re: IllegalArgumentException in batch execution
In-Reply-To: <384952.35231.qm@web110413.mail.gq1.yahoo.com>
References: <384952.35231.qm@web110413.mail.gq1.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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