Statement.getGeneratedKeys () and MySQL

I found out that this is difficult, since last_insert_id in mysql is not pool safe. those. if you join the connections you will encounter insert_ids. How does java statement.getGeneratedKeys () get key from inserts? Is he safe?

+3
source share
1 answer

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.

+3
source

Source: https://habr.com/ru/post/1767203/


All Articles