select max(_id) AS maxId from tableName String strSql = "select max(_id) AS maxId from tableName";Cursor mCursor = db.rawQuery(strSql, null);int maxId = cursor.getInt(cursor.getColumnIndex(maxId));
楼上已经给出了正确答案 max(_id)
嘿,你好,我使用上述代码的时候,出现了: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 异常,解决方法如下:Cursor mCursor = db.rawQuery(strSql, null); mCursor.moveToNext(); int maxId = mCursor .getInt(mCursor.getColumnIndex(maxId)); 你没有遇到过该异常吗?另:如有错误,欢迎指出。 Thanks.
哎,eclipse自动提示功能让程序员变弱智了
检查检查你的表数据和字段
Cursor cursor = db.query("table_name", null, null, null, null, null, "ORDER BY ID DESC");
if(cursor.moveToNext()
{
int id = cursor.getInt(cursor.getColumnIndex("_id"));
// 这个id就是最大值
}
Cursor c = ....String id = c.getString("_id", 0);
String strSql = "select max(_id) AS maxId from tableName";Cursor mCursor = db.rawQuery(strSql, null);int maxId = cursor.getInt(cursor.getColumnIndex(maxId));
max(_id)
嘿,你好,我使用上述代码的时候,出现了: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 异常,解决方法如下:Cursor mCursor = db.rawQuery(strSql, null);
mCursor.moveToNext();
int maxId = mCursor .getInt(mCursor.getColumnIndex(maxId)); 你没有遇到过该异常吗?另:如有错误,欢迎指出。
Thanks.