gpt4 book ai didi

java - statement.getGeneratedKeys() 和 MySQL

转载 作者:可可西里 更新时间:2023-11-01 08:22:23 25 4
gpt4 key购买 nike

我已经了解到 mysql 中的 last_insert_id 不是池安全的。也就是说,如果你正在合并连接,你会弄乱 insert_ids。java 的 statement.getGeneratedKeys() 如何获取插入的 key ?它对游泳池安全吗?

最佳答案

我引用了 MySQL Connector/J 中的相关文本 internals这里:

You 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.

关于java - statement.getGeneratedKeys() 和 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3823840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com