Cursor cursor = db.rawQuery("SELECT id,name FROM people WHERE id="+ id + " AND name IS NULL",null);
我不想只将一个 id 的记录加载到我的游标中,而是想加载一系列 id,例如从 id=100 到 id=150 到游标。我怎样才能做到这一点 ?
您可以通过更改WHERE
子句中使用的运算符来做到这一点。
SELECT id, name FROM people WHERE id>100 AND id<150 AND name IS NULL
试试这些查询
SELECT id, name FROM people WHERE id >= 100 AND id <= 150 AND name IS NULL
SELECT id, name FROM people WHERE id BETWEEN 100 AND 150 AND name IS NULL
Cursor cursor = db.rawQuery("SELECT id,name FROM people WHERE id <"+ upperBoundId + " AND id > " + lowerBoundId" + AND name IS NULL",null);
试试这个:
Cursor c = db.rawQuery("select id,name from people where id>100 and id<150 and name is null",null);
int Column1 = c.getColumnIndex("id");
int Column2 = c.getColumnIndex("name");
c.moveToFirst();
if (c != null) {
// Loop through all Results
do {
int id = c.getInt(Column1);
String name = c.getString(Column2);
}while(c.moveToNext());