As the title says, this is in java EE
, particularly java web. However, it is a simple% SQL
query:
I have a table with several data, and a id
autoincremental:
id, date, text.
I use a servlet to add an element to the database with the following query:
INSERT INTO tabla (fecha, texto) VALUES (valor1, valor2)
However, I want to get the ID
that was generated. What is the efficient way to do it?
It occurs to me to generate another query that obtains the last aggregate element, however, it seems inefficient to generate another query. Also, if 2 elements are added from different accounts at similar times, the codes could cross ... Any ideas? Do you know if it can be obtained from the same query?