PreparedStatement ps = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); // 第一步 ps.executeUpdate(); //第二步 ResultSet rs = ps.getGeneratedKeys(); //获取 rs.next(); int id = rs.getInt(1);