Java Basepeer - 获取上次插入记录的ID

时间:2018-02-08 08:34:59

标签: java

在php中,要获取最后插入记录的ID,我们这样做:

$last_id = mysqli_insert_id($conn);

我正试图通过doInsert(Criteria)实现这一目标。

据我从他们的文档中了解到,我这样做了:

Criteria criteria = new Criteria();
criteria.add(TABLE_NAME,"column1", val1);
criteria.add(TABLE_NAME,"column2", val2);
try {
    ObjectKey object = BasePeer.doInsert(criteria);
} catch (TorqueException e) {
    System.out.println(e.getMessage());
}

但是doInsert(Criteria)最终出现了NullPointerException。

1 个答案:

答案 0 :(得分:0)

尝试使用Java

检索sql_database中最后插入的记录
rs = st.executeQuery("select last_insert_id() as last_id from schedule");
lastid = rs.getString("last_id");
相关问题