Re: PreparedStatement.executeBatch() error? 7.3 - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: PreparedStatement.executeBatch() error? 7.3
Date
Msg-id 3E447AC3.2020101@xythos.com
Whole thread Raw
In response to PreparedStatement.executeBatch() error? 7.3  (Jeremiah Jahn <jeremiah@cs.earlham.edu>)
Responses Re: PreparedStatement.executeBatch() error? 7.3
List pgsql-jdbc
Jeremiah,

I am a bit confused.  You mention two different errors in your email the
  "ERROR:  parser:...." and the stack trace.  Do both get produced at
the same time, or are they happening at different times?

Also the parse error looks like an error coming from the database.  Can
you turn on query logging on the server to see the text of the statement
that the error is occuring in?  That should provide a clue as to why the
sql statement is invalid.

To log the sql statements on the server you want to set the parameter
log_statement=true in your postgresql.conf file.  Also it might help to
turn on debug logging in the jdbc driver.  Can you add ?loglevel=2 to
the jdbc connection url?  (both of the above suggestions are for 7.3,
the details on doing this on 7.2 are a bit different).

thanks,
--Barry


Jeremiah Jahn wrote:
> The following code doesn't work, but if in place of doing an addBatch
> loop with an executeBatch(), I do an executeUpdate each time it does
> work. I get a parse error from the db server:
>
> ERROR:  parser: parse error at or near "'1998CF43'" at character 4202
>
> this corresponds to the first value. I'm using the jdbc3 jar for this.
>
>  PreparedStatement pStatement = connection.prepareStatement("insert into case_data_store values (?,?,?,?)");
>         ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
>
>         for (int current_chunk = 0; current_chunk < chunk_count; current_chunk++){
>
>         pStatement.setString(1,values.get("CASENUMBER").toString());
>         pStatement.setString(2,values.get("NCIC").toString());
>         pStatement.setInt(3,current_chunk);
>         pStatement.setBytes(4,baos.toByteArray());
>         pStatement.addBatch();
>         //pStatement.executeUpdate();
>
>         }
>
>         pStatement.executeBatch();
>
>
>
> This is the stack trace:
> java.lang.ArrayIndexOutOfBoundsException: 1
>         at
> org.postgresql.core.QueryExecutor.sendQuery(QueryExecutor.java:143)
>         at
> org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:65)
>         at
> org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:451)
>         at
> org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:281)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
>         at
> org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:179)
>         at
> org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:165)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:80)
>
>




pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: examples of SQL Arrays and jdbc?
Next
From: "John Cavacas"
Date:
Subject: JDBC Error codes