pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedShould this code work??
4+ messages / 3 participants
[nested] [flat]
* Should this code work??
@ 2005-10-31 14:54 Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
0 siblings, 3 replies; 4+ messages in thread
From: Joost Kraaijeveld @ 2005-10-31 14:54 UTC (permalink / raw)
To: 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.Kraaijeveld@Askesis.nl
web: www.askesis.nl
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Should this code work??
@ 2005-10-31 15:12 Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
parent: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
2 siblings, 0 replies; 4+ messages in thread
From: Joost Kraaijeveld @ 2005-10-31 15:12 UTC (permalink / raw)
To: pgsql-jdbc
To answer my own question: because you did not call executeBatch() but
execute() ?
--
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Should this code work??
@ 2005-10-31 15:13 Rob Kirkbride <rob@rkcomputing.co.uk>
parent: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
2 siblings, 0 replies; 4+ messages in thread
From: Rob Kirkbride @ 2005-10-31 15:13 UTC (permalink / raw)
To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>; +Cc: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Should this code work??
@ 2005-10-31 15:22 Jan de Visser <jdevisser@digitalfairway.com>
parent: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
2 siblings, 0 replies; 4+ messages in thread
From: Jan de Visser @ 2005-10-31 15:22 UTC (permalink / raw)
To: pgsql-jdbc
On Monday 31 October 2005 09:54, Joost Kraaijeveld wrote:
> updateStatement.addBatch();
> }
>
> updateStatement.execute();
You need to call updateStatement.executeBatch()
HTH,
JdV!!
--
--------------------------------------------------------------
Jan de Visser jdevisser@digitalfairway.com
Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2005-10-31 15:22 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-31 14:54 Should this code work?? Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
2005-10-31 15:12 ` Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
2005-10-31 15:13 ` Rob Kirkbride <rob@rkcomputing.co.uk>
2005-10-31 15:22 ` Jan de Visser <jdevisser@digitalfairway.com>
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