pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Should this code work??
Date: Mon, 31 Oct 2005 15:54:12 +0100
Message-ID: <1130770452.3681.96.camel@Panoramix> (raw)

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 

view thread (4+ messages)  latest in thread

Message-ID: <1130770452.3681.96.camel@Panoramix>
Permalink:  ../1130770452.3681.96.camel@Panoramix/
Also on:    postgresql.org/message-id/1130770452.3681.96.camel@Panoramix

 · 

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: J.Kraaijeveld@Askesis.nl
  Subject: Re: Should this code work??
  In-Reply-To: <1130770452.3681.96.camel@Panoramix>
  References: <1130770452.3681.96.camel@Panoramix>

* 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