How to get Last Insert ID using SQLProcessor?

Mikhail_Kopylov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2013

I'm using org.ofbiz.core.entity.jdbc.SQLProcessor in JIRA 6.1 while working with some non-JIRA tables in database.

I want to insert some row into some table.

After executing

sqlProcessor.executeUpdate("INSERT INTO some_table (name) VALUES ('itemName')")

I've to get ID of the inserted row. In MySQL there's a function last_insert_id for that purpose.

How to get this ID using SQLProcessor?

1 answer

1 accepted

0 votes
Answer accepted
Mikhail_Kopylov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2013

For MySQL used MySQL function LAST_INSERT_ID();

After executing INSERT called this function in the second query.

For PostgreSQL called nextval() before INSERT, then, after getting ID, executed INSERT with all fields filled.

Suggest an answer

Log in or Sign up to answer