Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events