sqlite中的last_insert_id()CursorIndexOutOfBoundsException

时间:2013-06-15 16:39:54

标签: java android sqlite

任何人都可以看到此代码中的致命缺陷或消化替代方案吗?

int task_id = db.rawQuery("SELECT last_insert_rowid();", null).toInt(1);

在此行引发以下异常:

 android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

编辑: 想通了,空是问题。

正确的代码是:

 int task_id = db.rawQuery("SELECT last_insert_rowid();", new String[] {} ).getInt(0);

0 个答案:

没有答案