pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: luvar@plaintext.sk
To: Oliver Jowett <oliver@opencloud.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: bug in jdbc
Date: Mon, 5 Sep 2011 01:07:15 +0100 (GMT+01:00)
Message-ID: <1404320531.7051315181235186.JavaMail.root@shiva> (raw)
In-Reply-To: <237382761.7031315180992260.JavaMail.root@shiva>

----- "Oliver Jowett" <oliver@opencloud.com> wrote:

> On 4 September 2011 05:16,  <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)
> 
> Javadoc for getGeneratedKeys says:
> 
> 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.
> 
> 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 specification.

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.

> 
> Oliver



view thread (9+ messages)

Message-ID: <1404320531.7051315181235186.JavaMail.root@shiva>
Permalink:  ../1404320531.7051315181235186.JavaMail.root@shiva/
Also on:    postgresql.org/message-id/1404320531.7051315181235186.JavaMail.root@shiva

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: luvar@plaintext.sk, oliver@opencloud.com
  Subject: Re: bug in jdbc
  In-Reply-To: <1404320531.7051315181235186.JavaMail.root@shiva>
  References: <237382761.7031315180992260.JavaMail.root@shiva> <1404320531.7051315181235186.JavaMail.root@shiva>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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