pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Kirkbride <rob@rkcomputing.co.uk>
To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: Should this code work??
Date: Mon, 31 Oct 2005 15:13:00 +0000
Message-ID: <4366347C.6060305@rkcomputing.co.uk> (raw)
In-Reply-To: <1130770452.3681.96.camel@Panoramix>
References: <1130770452.3681.96.camel@Panoramix>

Joost Kraaijeveld wrote:

> Hi,
>
> Should this code work (it obviously doesn't but I want to know why):
>
> Class.forName("org.postgresql.Driver");
> Connection connection =  
> DriverManager.getConnection("jdbc:postgresql://muntserver:5432/muntdev","postgres", 
> "");
>
> Statement selectStatement = connection.createStatement();
> ResultSet resultSet = selectStatement.executeQuery(
> "select objectid, orderobjectid from prototype.orderlines");
>
> connection.setAutoCommit(false);
>
> PreparedStatement updateStatement =
> connection.prepareStatement("update prototype.orderlines set 
> ordernumber = (select ordernumber from prototype.orders where objectid 
> = ?) where objectid = ?");
>
> while( resultSet.next() )
> {
> if( (++record % 1000) == 0){
> System.err.println( "handling record: " + record);
> }
>
> updateStatement.setString(1,resultSet.getString("orderobjectid"));
> updateStatement.setString(2,resultSet.getString("objectid"));
>
> updateStatement.addBatch();
> }
>
> updateStatement.execute();
> connection.commit();
> selectStatement.close();
> updateStatement.close();
> connection.close();


It would help if you gave us the error that you're getting?

Rob



view thread (4+ messages)  latest in thread

Message-ID: <4366347C.6060305@rkcomputing.co.uk>
Permalink:  ../4366347C.6060305@rkcomputing.co.uk/
Also on:    postgresql.org/message-id/4366347C.6060305@rkcomputing.co.uk

 · 

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: rob@rkcomputing.co.uk, J.Kraaijeveld@Askesis.nl
  Subject: Re: Should this code work??
  In-Reply-To: <4366347C.6060305@rkcomputing.co.uk>
  References: <1130770452.3681.96.camel@Panoramix> <4366347C.6060305@rkcomputing.co.uk>

* 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