pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Björn Bergenheim <bjornJmagic@kenetworks.se>
To: pgsql-jdbc@postgresql.org
Subject: How to get batch commands to work
Date: Mon, 27 Feb 2006 00:59:22 +0100
Message-ID: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp> (raw)

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

view thread (2+ messages)  latest in thread

Message-ID: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp>
Permalink:  ../00d101c63b30$aa7a2b40$635a59d5@plyschmanxp/
Also on:    postgresql.org/message-id/00d101c63b30$aa7a2b40$635a59d5@plyschmanxp

 · 

reply

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: bjornJmagic@kenetworks.se
  Subject: Re: How to get batch commands to work
  In-Reply-To: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp>
  References: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp>

* 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