X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D64C652B9B for ; Wed, 13 Jul 2005 23:19:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27467-08 for ; Thu, 14 Jul 2005 02:19:51 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 971A252800 for ; Wed, 13 Jul 2005 23:19:50 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DstKM-0005Ir-95; Thu, 14 Jul 2005 14:19:54 +1200 Message-ID: <42D5CBC9.5000707@opencloud.com> Date: Thu, 14 Jul 2005 14:19:53 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Lenard, Rohan (Rohan)" Cc: pgsql-jdbc@postgresql.org Subject: Re: Multiple Statement result set problem with PreparedStatements References: <2773CAC687FD5F4689F526998C7E4E5F1EF340@au3010avexu1.global.avaya.com> In-Reply-To: <2773CAC687FD5F4689F526998C7E4E5F1EF340@au3010avexu1.global.avaya.com> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/mixed; boundary="------------010903040701090905010305" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/73 X-Sequence-Number: 13221 This is a multi-part message in MIME format. --------------010903040701090905010305 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Lenard, Rohan (Rohan) wrote: > I have one but it relies on particular tables existing - if I get a few > minutes I too will simplify it to cause it .. Hm, ok, try the attached testcase. It works fine for me here against 8.0.1 and 7.3.8 servers: > oliver@extrashiny ~/pgjdbc-test $ java -classpath .:/home/oliver/pgjdbc/jars/postgresql.jar TestMultiInsert 'jdbc:postgresql://localhost:5432/test?user=oliver' > Result #1 has resultset? false update count 1 > Result #2 has resultset? false update count 1 > Result #3 has resultset? true update count -1 > oliver@extrashiny ~/pgjdbc-test $ java -classpath .:/home/oliver/pgjdbc/jars/postgresql.jar TestMultiInsert 'jdbc:postgresql://localhost:5738/test?user=oliver' > Result #1 has resultset? false update count 1 > Result #2 has resultset? false update count 1 > Result #3 has resultset? true update count -1 Those are the results I was expecting, anyway.. were you expecting something different? -O --------------010903040701090905010305 Content-Type: text/plain; name="TestMultiInsert.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="TestMultiInsert.java" import java.sql.*; // Run with one argument: a JDBC url to connect to. public class TestMultiInsert { public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection c = DriverManager.getConnection(args[0]); c.setAutoCommit(false); Statement s = c.createStatement(); s.executeUpdate("CREATE SEQUENCE seq_i"); s.executeUpdate("CREATE SEQUENCE seq_j"); s.executeUpdate("CREATE TEMP TABLE t1 (i int4 default nextval('seq_i'), zz text)"); s.executeUpdate("CREATE TEMP TABLE t2 (j int4 default nextval('seq_j'), i int4, zz text)"); PreparedStatement ps = c.prepareStatement("INSERT INTO t1(zz) VALUES (?); INSERT INTO t2(i,zz) VALUES(currval('seq_i'),?); SELECT currval('seq_i'), currval('seq_j')"); ps.setString(1, "A"); ps.setString(2, "B"); boolean resultType = ps.execute(); int updateCount = ps.getUpdateCount(); int num = 1; do { System.err.println("Result #" + num + " has resultset? " + resultType + " update count " + updateCount); ++num; resultType = ps.getMoreResults(); updateCount = ps.getUpdateCount(); } while (resultType || updateCount != -1); s.close(); c.rollback(); c.close(); } } --------------010903040701090905010305--