PreparedStatement ps = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); // 第一步
ps.executeUpdate(); //第二步
ResultSet rs = ps.getGeneratedKeys(); //获取
rs.next();
int id = rs.getInt(1);
转载于:https://www.cnblogs.com/blogyuan/p/3739657.html