Skip to Content
Former Member
Jun 24, 2015 at 08:45 PM

How to retrieve row ID after insert?


Hi all!

I have a table that has 3 columns: ID, Name, LastVisit, wich are int, string, timestamp. I'm inserting data in this table and I need to retrieve the ID I just inserted. Problem is that the ID is a sequence. What I am trying to do is:

var insertCmd = connection.prepareStatement('insert into "Test"."TestTable"("ID", "Name", "LastVisit") values(seq.NEXTVAL,?,?)');


insertCmd.setString(2,"2015-06-22 00:00:00");

var test = insertCmd.execute();

var rowId = test.getString(1);

But I cannot get the rowId like I need to. Is there a way I can retrieve it? Thanks in advance!!