小编典典

获取MySQL中最后插入的自动增量ID

mysql

我正在尝试获取类似mysql_insert_id()的mysql命令;它检索最后插入的行的auto_increment
ID。我该怎么做才能在Java中获得它?

rs = st.executeQuery("select last_insert_id() from schedule");
lastid = rs.getString("last_insert_id()");

我的姓氏声明为INT。我不知道在rs.get中使用什么以及参数。


阅读 259

收藏
2020-05-17

共1个答案

小编典典

尝试使用别名

rs = st.executeQuery("select last_insert_id() as last_id from schedule");
lastid = rs.getString("last_id");
2020-05-17