Subject Re: [Firebird-Java] Re: Getting a reference after insert
Author Rick Fincher
Thanks Roman,

How about: statement.getGeneratedKeys()? Does the driver support this call?

As I understand it I can do:

Statement.executeUpdate(sql insert string, String[] columnNames);
ResultSet rs = Statement.getGeneratedKeys();

Then get the key from the result set rs.

The reason I ask is that a lot of calls weren't supported in Interclient and
there's no documentation that I know of listing which are supported in the
new driver.

Thanks Again,


----- Original Message -----

> Hi,
> > Forgive my ignorance about SQL, but is there a way to get the primary
> > key back of a record that is inserted? I know I can do a search on the
> > same record data, but it is not guaranteed to be distinct. Do any of
> > the driver call return this to the calling java program?
> Since you've used magic word "java" you're not bounced to IB-Support
> list :)
> As far as I know there is no chance to get value of an ID generated
> during execution of INSERT ... statement. You can either select next
> ID directly before executing INSERT with
> SELECT gen_id(my_generator, 1) FROM RDB$DATABASE
> or you can get a block of IDs (for example 100) using
> SELECT gen_id(my_generator, 100) FROM RDB$DATABASE
> and then set them directly in your INSERT statement ("select ... from
> rdb$database" returns you exactly one row). If you have other
> applications that assume that ID is generated automatically, you can
> modify your trigger so it does not generate new ID if your primary key
> is not null.
> But in general, such questions should be posted to IB-Support group,
> you would get better feedback there.
> Best regards,
> Roman Rokytskyy