String sql = "insert into table values(...)"
objConn.executeUpdate(sql)
下面是取刚插入数据库的ID号
long ret_id=0
ResultSet rs = objConn.executeQuery("select LAST_INSERT_ID()")
if (rs.next())ret_id = rs.getLong(1)
在你执行插入语句后,随后执行这个查询:ResultSet rs=st.executeQuery("SELECT @@IDENTITY AS currentID")
if(rs.next()){
System.out.println(rs.getLong("currentID"))//返回id
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)