Re: Should this code work??

From: Rob Kirkbride <rob(at)rkcomputing(dot)co(dot)uk>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Should this code work??
Date: 2005-10-31 15:13:00
Message-ID: 4366347C.6060305@rkcomputing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jan de Visser 2005-10-31 15:22:32 Re: Should this code work??
Previous Message Joost Kraaijeveld 2005-10-31 15:12:17 Re: Should this code work??