当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Auto generated key in mysql jdbc

问题描述:

i am not getting the auto generated key from 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);

output:

2>>>>>>>>0 [email protected]

网友答案:

Write resultset.executeQuery and then call getGeneratedKey

分享给朋友:
您可能感兴趣的文章:
随机阅读: