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);
网友评论