java – 在mysql中获取最后插入的auto increment id

前端之家收集整理的这篇文章主要介绍了java – 在mysql中获取最后插入的auto increment id前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图得到像 mysql_insert_id()的MysqL命令;它检索最后插入的行的auto_increment id.我可以用 Java做什么?
  1. rs = st.executeQuery("select last_insert_id() from schedule");
  2. lastid = rs.getString("last_insert_id()");

我的lastid被宣布为INT.我没有在rs.get中使用什么,还有参数..

解决方法

尝试使用别名
  1. rs = st.executeQuery("select last_insert_id() as last_id from schedule");
  2. lastid = rs.getString("last_id");

猜你在找的Java相关文章