我已经学会了很难在mysql中last_insert_id不是池安全的.即,如果您正在池化连接,则会搞砸insert_ids.
java的statement.getGeneratedKeys()如何获取插入的键?游泳池安全吗?
最佳答案
我在这里引用了MySQL Connector / J internals的相关文本:
原文链接:https://www.f2er.com/mysql/532178.htmlYou should be aware,that at times,it
can be tricky to use the ‘SELECT
LAST_INSERT_ID()’ query,as that
function’s value is scoped to a
connection. So,if some other query
happens on the same connection,the
value will be overwritten. On the
other hand,the ‘getGeneratedKeys()’
method is scoped by the Statement
instance,so it can be used even if
other queries happen on the same
connection,but not on the same
Statement instance.