Java – get the inserted ID in the same statement

There is already an answer to this question: > how to get the insert ID in JDBC? six

Thanks for your help.

John polkley

Solution

Use getgeneratedkeys():

resultSet = pstmt.getGeneratedKeys(); 

if (resultSet != null && resultSet.next()) { 
    lastId = resultSet.getInt(1); 
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>