1

我没有从 mysql 获取自动生成的密钥

String query="insert into course(subject,board,standard,course_code)values(?,?,?,?)";
            st1 = con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
            st1.setString(1, sub);
            st1.setString(2, board);
            st1.setString(3, std);
            st1.setString(4, course);

            rs1 = st1.getGeneratedKeys();
            if (rs1.next()){
                cid=rs1.getInt(1);
            }
            System.out.println("2>>>>>>>>" + cid+" "+rs1);

输出:

2>>>>>>>>0 com.mysql.jdbc.JDBC4ResultSet@1b04d3d
4

1 回答 1

2

resultset.executeQuery然后打电话getGeneratedKey

于 2013-03-31T08:28:24.283 回答