Subject Re: [Firebird-Java] Re: returning generated keys
Author Nikolay Ivanchev
Actualy I faced the same problem, developing CRM application based on Firebird
I am using sessions and have additional column (for example fresh). Whein I insert a row
I set fresh=0;
then I select all rows with fresh=0 and get the ID (autogenerated) .. then using the ID I set fresh to 1...
all this done in high level of transaction isolation and in one transaction. This works for me
 
niki_iv
----- Original Message -----
Sent: Thursday, March 27, 2003 10:19 AM
Subject: [Firebird-Java] Re: returning generated keys

> I note that a call to
>
> Statement.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS)
>
> currently raises an exception with a 'not yet implemented'
> message.  I imagine this has a lot to do with there being
> no 'autoinc' type in firebird? (yes I'm using a trigger and a
> generator).

You are right. This method does not works because server does not
have autoinc datatype.

> Does anyone have a clever and (most importaintly) portable way of
> doing the same thing?  Although we are currently using Firebird for
> development, ultimatly our clients will be making the call as to
> which database the app will run on so we need to keep it all as
> generic as possible.

Split ID generation and statement execution into two separate steps.
You can decide if you want to make these steps visible on the
interface level, or only in the implementation.

Another approach can be creating a stored procedure that performs
insert and returns you generated ID. But in this case you need to use
CallableStatement or PreparedStatement.executeQuery().

Best regards,
Roman Rokytskyy



To unsubscribe from this group, send an email to:
Firebird-Java-unsubscribe@yahoogroups.com



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.