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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-jdbc by date

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