我的光标似乎不起作用。有人能帮帮我吗?实际上这里的 for 循环不起作用。未显示日志。这是我的代码:
public String getAFact(int rowNumber)
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("select mfacts from mfacts where osl_number=" + rowNumber + ";", null);
for(c.moveToFirst();!c.isAfterLast();c.moveToNext()) {
rowData = c.getString(c.getColumnIndex(KEY_NAME));
Log.i("log_tag", "cursor isn't f**ked up..."+rowData);
}
c.close();
db.close();
return rowData;
}
}
但无论如何,以下代码工作正常,并且正确显示了记录数!
public int countRowsInDb()
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("select * from mfacts",null);
Log.i("Number of Records"," :: "+c.getCount());
db.close();
int c_getCount = c.getCount();
c.close();
return c_getCount;
}