我没有从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
最佳答案
写入resultset.executeQuery
然后调用getGeneratedKey
关于java - mysql jdbc中自动生成的 key ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15727731/