How to get the insert ID in JDBC?

后端 未结 12 2037
暖寄归人
暖寄归人 2020-11-21 06:09

I want to INSERT a record in a database (which is Microsoft SQL Server in my case) using JDBC in Java. At the same time, I want to obtain the insert ID. How can

12条回答
  •  不要未来只要你来
    2020-11-21 06:43

    If you are using Spring JDBC, you can use Spring's GeneratedKeyHolder class to get the inserted ID.

    See this answer... How to get inserted id using Spring Jdbctemplate.update(String sql, obj...args)

提交回复
热议问题