How to get element id just inserted - JAVA [duplicate]

1

How do I get a id of an element just inserted in the Database in Java? Something like: mysql_insert_id() no PHP .

    
asked by anonymous 05.02.2017 / 17:44

1 answer

1

Within a transaction , shortly after inserting into the database and before performing commit , you can SELECT id FROM tabela WHERE ROWNUM = 1 ORDER BY id DESC (SQL for Oracle). This query will return the last id inserted.

SQL may vary by your bank, but the idea is that.

    
06.02.2017 / 16:45