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 21D85DB52F for ; Mon, 31 Oct 2005 11:13:02 -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 24317-02 for ; Mon, 31 Oct 2005 15:12:58 +0000 (GMT) Received: from mra02.ch.as12513.net (mra02.ch.as12513.net [82.153.252.24]) by svr1.postgresql.org (Postfix) with ESMTP id B861CDB304 for ; Mon, 31 Oct 2005 11:13:00 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mra02.ch.as12513.net (Postfix) with ESMTP id E3ACDD4423; Mon, 31 Oct 2005 15:13:03 +0000 (GMT) Received: from mra02.ch.as12513.net ([127.0.0.1]) by localhost (mra02.ch.as12513.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 30502-01-86; Mon, 31 Oct 2005 15:13:02 +0000 (GMT) Received: from [10.0.0.150] (unknown [81.5.146.249]) by mra02.ch.as12513.net (Postfix) with ESMTP id CC028D4432; Mon, 31 Oct 2005 15:13:01 +0000 (GMT) Message-ID: <4366347C.6060305@rkcomputing.co.uk> Date: Mon, 31 Oct 2005 15:13:00 +0000 From: Rob Kirkbride User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Joost Kraaijeveld Cc: "pgsql-jdbc@postgresql.org" Subject: Re: Should this code work?? References: <1130770452.3681.96.camel@Panoramix> In-Reply-To: <1130770452.3681.96.camel@Panoramix> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by Eclipse VIRUSshield at eclipse.net.uk X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200510/157 X-Sequence-Number: 14088 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