Question
Nicola Sartore · Nov 4, 2021

How to get the insert ID in SQL?

I want to INSERT a record in a database using JDBC in  OBJECTSCRIPT. At the same time, I want to obtain the insert ID. Is there a way to achieve this using the SQL Outbound adapter?

My code is something like this now:


Property Adapter As EnsLib.SQL.OutboundAdapter;

set sql = " INSERT INTO Prenotazioni_CUP "_
                  " (ID, cf
                  " VALUES (SEQTAB.NextVal, ?) "
set status = ..Adapter.ExecuteUpdate(.rs, sql, pRequest.cfAssistito)

Product version: IRIS 2021.1
0
0 243
Discussion (5)1
Log in or sign up to continue

??? you seem to insert the ID already  ???
set sql = " INSERT INTO Prenotazioni_CUP "_" (ID, cf)"_" VALUES (SEQTAB.NextVal, ?) 
??? not clear what you are looking for ???

Yes in this case I can simply retrieve the ID SEQTAB.NextVal with another query. Thanks.

Try getGeneratedKeys() function 
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=BGJD_coding

Thanks

Would be great, but I don t have access to the java.sql package in my environment. Thank you for the answer anyway.

Try getGeneratedKeys() function 
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=BGJD_coding

Thanks