Hi,

The standardized way is using the JDBC API, Statement.getGeneratedKeys:

http://h2database.com/javadoc/org/h2/jdbc/JdbcStatement.html#getGeneratedKeys

For MS SQL Server compatibility, H2 also supports IDENTITY and
SCOPE_IDENTITY:

http://h2database.com/html/functions.html#scope_identity

Regards,
Thomas


On Tue, Aug 7, 2012 at 7:00 AM, Noel L <[email protected]> wrote:

> Hi Ugo,
>
> In tables where I have used an auto generated ID, the latest ID is always
> the highest number.  So I use SELECT max(ID) FROM <filename>.  There may be
> a better way to do it, but this works fine for me.
>
> Noel
>
>
> On Tuesday, August 7, 2012 3:41:48 AM UTC+10, Ugo Matrangolo wrote:
>>
>> Hi,
>>
>> I need to know the auto generated ID of the last entity that was just
>> persisted on the db using an INSERT operation.
>>
>> On PostGRES I was used to the `... returning id` statement at the end of
>> the INSERT operation. This seems to be missing from H2.
>>
>> How can I get the same behavior ???
>>
>> Cheers,
>> Ugo.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/h2-database/-/6XUyWiID7rAJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to