我在SQLite中有这个表 然后我有这个代码,我希望得到所有的行值
SQLiteDatabase db = dbModel.getReadableDatabase();
Cursor c = db.rawQuery("SELECT cig_for_this_day FROM program WHERE stage = 2", null);
if (c.moveToFirst()) {
int rows = c.getCount();
while (c.isAfterLast() == false) {
int j = c.getInt(0);
c.moveToNext();
}
}
c.close();
db.close();
它可以获得计数,但每次循环都返回12,为什么会发生这种情况,我希望它一直移动到列的末尾
答案 0 :(得分:0)
像这样改变循环:
...
if (c.moveToFirst()) {
int rows = c.getCount();
do {
int j = c.getInt(0);
// Do something with j
} while(c.moveToNext());
}
...