java - Spring JDBC使用什么方法获取最新的key

标签 java mysql spring

以下 YSQL 文档:doc最后一段提到:

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

当我在完全分布式的环境中工作时,不要碰巧从数据库中获取错误的 key 对我来说非常重要......

springJDBC正在使用这些方法中的哪一个

我正在使用 spring 版本 3.2.1.RELEASE 但我不打算升级到最新版本。

最佳答案

嗯。按照建议,我仔细研究了代码,直到到达这一行。

ResultSet keys = ps.getGeneratedKeys();

PreparedStatementCallback 匿名类内部调用。

因此,出于所有意图和目的,该函数: int org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder) 抛出 DataAccessException

这是一个线程/进程安全的操作

关于java - Spring JDBC使用什么方法获取最新的key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26083167/

相关文章:

java - Querydsl 有哪些好的用例?

java - 将路径图像从java发送到python

java - 创建名称为 ‘client’ 的 bean 时出错

Spring 安全 JavaConfig : IllegalArgumentException: 'name' must not be null

java - 无法读取Spring应用程序中的POST参数

java - Android Studio中添加JsonPath导致非零退出值2错误

mysql - 当我使用 --databases ='mydb' 指定时,innobackupex 始终备份 ibdata1

php - 基本注册表单

mysql - 如何使用连接获取正确的值

java - Information_schema 不是从 jooq for SQL Server 生成的