X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 42A87DB528 for ; Mon, 31 Oct 2005 10:54:12 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15552-02 for ; Mon, 31 Oct 2005 14:54:08 +0000 (GMT) Received: from obelix.askesis.nl (laudanum.demon.nl [82.161.125.16]) by svr1.postgresql.org (Postfix) with ESMTP id 29463DB4FF for ; Mon, 31 Oct 2005 10:54:09 -0400 (AST) Received: obelix.askesis.nl 172.31.0.1 from 172.31.1.8 172.31.1.8 via HTTP with MS-WebStorage 6.0.6249 Received: from Panoramix by obelix.askesis.nl; 31 Oct 2005 15:54:12 +0100 Subject: Should this code work?? From: Joost Kraaijeveld To: "pgsql-jdbc@postgresql.org" Content-Type: multipart/alternative; boundary="=-axfyw2f+n5NeXzemkxXd" Date: Mon, 31 Oct 2005 15:54:12 +0100 Message-Id: <1130770452.3681.96.camel@Panoramix> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.077 required=5 tests=[AWL=0.075, HTML_MESSAGE=0.001, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.077 X-Spam-Level: X-Archive-Number: 200510/155 X-Sequence-Number: 14086 --=-axfyw2f+n5NeXzemkxXd Content-Type: text/plain Content-Transfer-Encoding: 7bit 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(); Sorry about the HTML but for some reason my email editor suddenly insists on wrapping otherwise. -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 e-mail: J.Kraaijeveld@Askesis.nl web: www.askesis.nl --=-axfyw2f+n5NeXzemkxXd Content-Type: text/html; charset=utf-8 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();

Sorry about the HTML but for some reason my email editor suddenly insists on wrapping otherwise.

-- 
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J.Kraaijeveld@Askesis.nl
web: www.askesis.nl 


--=-axfyw2f+n5NeXzemkxXd--