如何在SQLite,Android中对整数字段执行选择查询?

时间:2015-12-14 17:25:10

标签: android database sqlite

SQLiteDatabase database = this.getReadableDatabase();
        Cursor cursor = database.rawQuery(selectAll + DatabaseSchema.Vehicles.TABLE_NAME + " where " + DatabaseSchema.Vehicles.COLUMN_ID + "=" + id, null);
        cursor.moveToFirst();

此处,selectAll = "select * from "COLUMN_ID具有int数据类型。此代码每次都返回一个空光标。即使数据插入表中。 当我仅使用" select * from tablename"运行查询时。它给了我数据。

1 个答案:

答案 0 :(得分:1)

I think that your problem is when you are accesing with cursor.moveToFirst(); try this instead:

SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.rawQuery(selectAll + DatabaseSchema.Vehicles.TABLE_NAME + " where " + DatabaseSchema.Vehicles.COLUMN_ID + "=" + id, null);
if (cursor != null && cursor.moveToFirst()) {
    do {
    //Do your stuff!
    } while (cursor.moveToNext());
}
cursor.close();