From: Kris Jurka <books@ejurka.com>
To: Björn Bergenheim <bjornJmagic@kenetworks.se>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: How to get batch commands to work
Date: Mon, 27 Feb 2006 17:14:30 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0602271713090.283@leary.csoft.net> (raw)
In-Reply-To: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp>
References: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp>
On Mon, 27 Feb 2006, Björn Bergenheim wrote:
> 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":
>
This should work fine as the attached test does for me. Can you show us a
complete example of something that fails?
Kris Jurka
Attachments:BatchTest.java (text/plain, 770B) download
import java.sql.*;
public class BatchTest {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka","");
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMP TABLE t (a int primary key)");
PreparedStatement ps = conn.prepareStatement("INSERT INTO t VALUES (?)");
ps.setInt(1,1);
ps.addBatch();
ps.setInt(1,2);
ps.addBatch();
ps.executeBatch();
ps.setInt(1,3);
ps.addBatch();
ps.executeBatch();
ps.close();
ResultSet rs = stmt.executeQuery("SELECT a FROM t");
while (rs.next()) {
System.out.println(rs.getInt(1));
}
}
}
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: books@ejurka.com, bjornJmagic@kenetworks.se
Subject: Re: How to get batch commands to work
In-Reply-To: <Pine.BSO.4.63.0602271713090.283@leary.csoft.net>
References: <00d101c63b30$aa7a2b40$635a59d5@plyschmanxp> <Pine.BSO.4.63.0602271713090.283@leary.csoft.net>
* 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