获得从SQLite数据库Android的最后一个插入值 [英] Get last inserted value from sqlite database Android
问题描述
我想从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的最佳方式。 您可以检查它的文档<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert%28java.lang.String,%20java.lang.String,%20android.content.ContentValues%29">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.
我希望这有助于。
这篇关于获得从SQLite数据库Android的最后一个插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!