I quote the corresponding text from the MySQL Connector / J interface here:
You should be aware that at times it can be difficult to use "SELECT" LAST_INSERT_ID (), since this function value is limited to connect. So, if some other request happens on the same connection, the value will be overwritten. On the other hand, the 'getGeneratedKeys ()' method is defined by the Law instance, so it can be used even if other requests occur on the same connection, but not on the same Instance of the instance.
source
share