Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id AA174B5DC9D for ; Sun, 4 Sep 2011 21:07:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 03962-04 for ; Mon, 5 Sep 2011 00:07:17 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from shiva.plaintext.sk (mail.plaintext.sk [81.0.124.6]) by mail.postgresql.org (Postfix) with ESMTP id 3912AB5DC99 for ; Sun, 4 Sep 2011 21:07:16 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by shiva.plaintext.sk (Postfix) with ESMTP id B4F0F26C8E; Mon, 5 Sep 2011 02:07:15 +0200 (CEST) X-Virus-Scanned: amavisd-new at plaintext.sk Received: from shiva.plaintext.sk ([127.0.0.1]) by localhost (shiva.plaintext.sk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 35FwWdLIj5vu; Mon, 5 Sep 2011 02:07:15 +0200 (CEST) Received: from shiva.plaintext.sk (shiva.plaintext.sk [81.0.124.6]) by shiva.plaintext.sk (Postfix) with ESMTP id 5677C26C87; Mon, 5 Sep 2011 02:07:15 +0200 (CEST) Date: Mon, 5 Sep 2011 01:07:15 +0100 (GMT+01:00) From: luvar@plaintext.sk To: Oliver Jowett Cc: pgsql-jdbc@postgresql.org Message-ID: <1404320531.7051315181235186.JavaMail.root@shiva> In-Reply-To: <237382761.7031315180992260.JavaMail.root@shiva> Subject: Re: bug in jdbc MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Mailer: Zimbra 5.0.16_GA_2921.UBUNTU8_64 (ZimbraWebClient - FF3.0 (Linux)/5.0.16_GA_2921.UBUNTU8_64) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/7 X-Sequence-Number: 22125 ----- "Oliver Jowett" wrote: > On 4 September 2011 05:16, wrote: > > Hi, I have executed some update query and I have requested to return > generated id... > > > > statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); > > ResultSet ids =C2=A0=3D statement.getGeneratedKeys(); > > ids.next(); > > ids.getInt(1); > > > > It will fail with this exception: > > > > 19:03:50,300 =C2=A0 =C2=A0 =C2=A0 =C2=A0 WARN ObjectBrowser:254 - Bad v= alue for type int > : /home/luvar/output.svg > > org.postgresql.util.PSQLException: Bad value for type int : > /home/luvar/output.svg > > =C2=A0 =C2=A0 =C2=A0 =C2=A0at > org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.= java:2759) > > =C2=A0 =C2=A0 =C2=A0 =C2=A0at > org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet= .java:2003) >=20 > Javadoc for getGeneratedKeys says: >=20 > Note:If the columns which represent the auto-generated keys were not > specified, the JDBC driver implementation will determine the columns > which best represent the auto-generated keys. >=20 > So you shouldn't expect a particular set of returned columns unless > you explicitly specify which columns to return. (In this particular > case the driver is playing it safe and returning *all* columns as it > doesn't know which ones could be affected by triggers etc) > You could look up the column you want by name rather than by index, > or > use the overloaded variant of executeUpdate() that takes a list of > column names. Many thanks for clarification. So this behavior is in line with specificati= on. To be accurate, I should call something like: statement.executeUpdate(query, new String[] {"id"}); instead of: statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); to get only autogenerated (in my case "id") column. Please correct me, If I= am wrong. >=20 > Oliver