From: | Daryl Beattie <dbeattie(at)insystems(dot)com> |
---|---|
To: | 'Michael Paesold' <mpaesold(at)gmx(dot)at>, pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: JDBC and fetching the OID of an insert |
Date: | 2002-09-18 13:53:44 |
Message-ID: | 4160E6FC08ABD21191F000805F857E9305ECE400@mail.markham.insystems.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Dear Michael,
I asked this question a little while back too. :) I'm sure it is a
question that comes up quite often.
The simple answer that I got is to do:
SELECT nextval(columnName);
INSERT INTO tableName (columnName) VALUES ([result of first query]);
through JDBC calls. If the insert fails, nothing is lost. No real
need for a transaction here.
I cannot speak on whether or not getGeneratedKeys() is
supported/implemented in the JDBC driver.
Yes, you are correct in assuming that the only way to get a value
for a sequence via JDBC is to "SELECT currval('...')" resp. "SELECT
nextval('...')".
Sincerely,
Daryl.
> -----Original Message-----
> From: Michael Paesold [mailto:mpaesold(at)gmx(dot)at]
> Sent: Wednesday, September 18, 2002 9:37 AM
> To: pgsql-jdbc(at)postgresql(dot)org
> Subject: [JDBC] JDBC and fetching the OID of an insert
>
>
> Hi,
>
> Does anyone of you know, how to get the OID of the just
> inserted Row after
> stmt.executeUpdate("INSERT... ")? I hope this is possible at all!
>
> If it's not, I would be willing to implement
> getGeneratedKeys() to return at
> least the OID of an insert. Assuming that would be possible
> and exceptable?
>
> (Btw. am I correct that the only way to get a value for a
> sequence via JDBC
> is to "SELECT currval('...')" resp. "SELECT nextval('...')"?)
>
>
> Best Regards,
> Michael
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2002-09-18 14:04:13 | Re: JDBC and fetching the OID of an insert |
Previous Message | Michael Paesold | 2002-09-18 13:36:34 | JDBC and fetching the OID of an insert |