From: | luvar(at)plaintext(dot)sk |
---|---|
To: | Oliver Jowett <oliver(at)opencloud(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: bug in jdbc |
Date: | 2011-09-05 00:07:15 |
Message-ID: | 1404320531.7051315181235186.JavaMail.root@shiva |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
----- "Oliver Jowett" <oliver(at)opencloud(dot)com> wrote:
> On 4 September 2011 05:16, <luvar(at)plaintext(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Olivier Thomas | 2011-09-05 14:36:15 | Postgres jdbc transactions |
Previous Message | Oliver Jowett | 2011-09-04 21:25:14 | Re: bug in jdbc |