Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D8D4BB5DC27 for ; Sun, 4 Sep 2011 13:45:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 18336-02 for ; Sun, 4 Sep 2011 16:45:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outbound.vnet-inc.com (outbound.vnet-inc.com [216.146.104.103]) by mail.postgresql.org (Postfix) with ESMTP id 6D654B5DC26 for ; Sun, 4 Sep 2011 13:45:44 -0300 (ADT) Received: from [192.168.157.132] (unknown [76.75.27.41]) by outbound.vnet-inc.com (Postfix) with ESMTP id DDBF759B8; Sun, 4 Sep 2011 10:45:44 -0600 (MDT) Message-ID: <4E63AA4A.6010201@ttc-cmc.net> Date: Sun, 04 Sep 2011 10:41:46 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: luvar@plaintext.sk, pgsql-jdbc@postgresql.org Subject: Re: bug in jdbc References: <381613887.6661315070190151.JavaMail.root@shiva> <4E63A7C4.3040909@ttc-cmc.net> In-Reply-To: <4E63A7C4.3040909@ttc-cmc.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/5 X-Sequence-Number: 22123 dmp wrote: > luvar@plaintext.sk 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 = statement.getGeneratedKeys(); >> ids.next(); >> ids.getInt(1); >> >> It will fail with this exception: >> >> 19:03:50,300 WARN ObjectBrowser:254 - Bad value for type int : >> /home/luvar/output.svg >> org.postgresql.util.PSQLException: Bad value for type int : >> /home/luvar/output.svg >> at >> org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2759) >> >> at >> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2003) >> >> ..... >> >> >> I am using maven. Used jdbc version: >> >> >> postgresql >> postgresql >> 9.0-801.jdbc4 >> >> >> I have table constructed in such way, that id (bigserial typed) column >> is NOT first column. It is second and first column of my table is >> "url" column to which I try insert "/home/luvar/output.svg" value. >> >> Can you have a look and confirm this bug to me, or there is no bug and >> something I am doing bad? >> > > I have confirmed the behavior you have indicated in a test case that > is not using Maven, but rather the JDBC directly. > > Though I have not reviewed the behavior of statement.executeUpdate(query, > Statement.RETURN_GENERATED_KEYS) thoroughly I suggest you try the > modifications that I made to your example code that helped me to understand > more fully what is happening. I can not address if this is a bug or not. > > sqlStatement.executeUpdate(sqlStatementString, > Statement.RETURN_GENERATED_KEYS); > resultSet = sqlStatement.getGeneratedKeys(); > tableMetaData = resultSet.getMetaData(); > while (resultSet.next()) > { > for (int i = 1; i < tableMetaData.getColumnCount() + 1; i++) > { > System.out.println(i + " " + tableMetaData.getColumnName(i)); > System.out.println(resultSet.getString(colNameString)); > } > } > > Output: > Connection Created > INSERT INTO "public"."key_table21" ("text","id") VALUES ('aaa',33) > 1 text > aaa > 2 id > 33 > Connection Closed > > danap. > Sorry I made a simplification of the example code in the email that obscured it. while (resultSet.next()) { for (int i = 1; i < tableMetaData.getColumnCount() + 1; i++) { String colNameString = tableMetaData.getColumnName(i); System.out.println(i + " " + colNameString); System.out.println(resultSet.getString(colNameString)); } } danap.