获得从SQLite数据库Android的最后一个插入值数据库、SQLite、Android

2023-09-12 21:49:58 作者:所谓的学霸就是不学也罢

我想从Android的SQLite数据库得到最后插入的ROWID。我读了很多关于它的帖子,却无法得到一个工作。 这是我的方法:

I am trying to get the last inserted rowid from a sqlite database in Android. I have read a lot of posts about it, but can't get one to work. This is my method:

 public Cursor getLastId() {
        return mDb.query(DATABASE_TABLE, new String[] {KEY_WID}, KEY_WID + "=" + MAX(_id), null, null, null, null, null);}

我曾尝试与MAX,但我一定要使用它错了。有另一种方式?

I have tried with MAX, but I must be using it wrong. Is there another way?

推荐答案

那么实际上是SQLiteDatabase类有返回新创建的行的id自己的插入方法。我认为这是获得新的ID的最佳方式。 您可以检查它的文档here.

Well actually the SQLiteDatabase class has its own insert method which returns the id of the newly created row. I think this is the best way to get the new ID. You can check its documentation here.

我希望这有助于。