Re: PreparedStatement.executeBatch() error? 7.3 - Mailing list pgsql-jdbc
From | Kris Jurka |
---|---|
Subject | Re: PreparedStatement.executeBatch() error? 7.3 |
Date | |
Msg-id | Pine.LNX.4.33.0302090407170.29526-100000@leary.csoft.net Whole thread Raw |
In response to | PreparedStatement.executeBatch() error? 7.3 (Jeremiah Jahn <jeremiah@cs.earlham.edu>) |
List | pgsql-jdbc |
I've been unable to reproduce this with the current 7.3 driver and the following code. You will need to provide a some more detail if you're still experiencing this problem. Kris Jurka import java.sql.*; public class BatchPstmt { // CREATE TABLE batchstmt(a text, b varchar(50), c int, d bytea); public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka",""); PreparedStatement pstmt = conn.prepareStatement("insert into batchpstmt values (?,?,?,?)"); byte bytes[] = new byte[0]; for (int i=0; i<5; i++) { pstmt.setString(1,"CASENUMBER"); pstmt.setString(2,"NCIC"); pstmt.setInt(3,i); pstmt.setBytes(4,bytes); pstmt.addBatch(); } pstmt.executeBatch(); pstmt.close(); conn.close(); } } On 7 Feb 2003, 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) > > > -- > Jeremiah Jahn <jeremiah@cs.earlham.edu> > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >
pgsql-jdbc by date: