欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获得插入数据的自增id

程序员文章站 2022-06-05 09:19:16
...
String sql = "insert into userinfo values ('张三')";  
PreparedStatement stmt = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);  
stmt.executeUpdate();  
ResultSet rs = stmt.getGeneratedKeys();  
int newid = 0;  
if(rs.next()) newid = rs.getInt(1);  

转载于:https://www.jianshu.com/p/7cf3756f00cd