How to get batch commands to work

From: Björn Bergenheim <bjornJmagic(at)kenetworks(dot)se>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: How to get batch commands to work
Date: 2006-02-26 23:59:22
Message-ID: 00d101c63b30$aa7a2b40$635a59d5@plyschmanxp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello all, I have tried to check out the archive since this seems like a question I shouldnt be the first to ask, but I have come up with nothing. I'm doing a massive insert batch, and thought that you could add a few insert to a batch, and then execute the batch, and then continue adding more inserts, and then run the batch, and so on. However, when I try to do this, I get an exception when I try to populate my prepared statement after I have run the executeBatch() for the first time. The eception I get is "Parameter index out of range":

Caused by: Parameter index out of range.
at org.postgresql.jdbc1.AbstractJdbc1Statement.bind(AbstractJdbc1Statement.java:1743)
at org.postgresql.jdbc1.AbstractJdbc1Statement.setInt(AbstractJdbc1Statement.java:782)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.postgresql.ds.common.PooledConnectionImpl$StatementHandler.invoke(PooledConnectionImpl.java:467)
at $Proxy2.setInt(Unknown Source)
at com.frontvision.nemo2.utilities.hostip.Importer.insertCountries(Importer.java:287)
at com.frontvision.nemo2.utilities.hostip.Importer.read(Importer.java:216)
... 15 more

I have a pstmt which I use, and in a loop adds stuff to it like this:
pstmt.setInt(1,countryId);
pstmt.setString(2, countryName);
pstmt.setString(3, shortContryName);
pstmt.addBatch();

then after say 200 of these batches, I do a
if(counter%200 = 0)
{
pstmt.executeBatch();
}
and then continue to add to the batch. Have I got this completly wrong, ei is this not the correct way to do it, or is there something fishy with my db or jdcb drivers? I'm using win8.0 version and jdbc 8.0-314,jdbc3.jar

/Bjorn

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Markus Schaber 2006-02-27 10:38:26 Re: Retrieve Query
Previous Message Ali Vatani 2006-02-25 03:09:13 postgres PreparedStatement commented ? problem PSQLException: No value specified for parameter ...