Skip site navigation (1) Skip section navigation (2)

Should this code work??

From: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
To: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Should this code work??
Date: 2005-10-31 14:54:12
Message-ID: 1130770452.3681.96.camel@Panoramix (view raw or flat)
Thread:
Lists: pgsql-jdbc
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(dot)Kraaijeveld(at)Askesis(dot)nl
web: www.askesis.nl 


Responses

pgsql-jdbc by date

Next:From: Joost KraaijeveldDate: 2005-10-31 15:12:17
Subject: Re: Should this code work??
Previous:From: Kris JurkaDate: 2005-10-31 06:45:53
Subject: Re: Updated french translation for HEAD

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group