public Cursor legsWorkout(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select count(*) from " + TABLE_W + " where w1="+ "Legs" + " or w2="
+ "Legs" + " or w3=" + "Legs",null);
return res;
}
///other part
Cursor res = myDB.bicepsWorkout();
while (res.moveToFirst()){
int totalCount = res.getInt(0);
txtTest.setText(String.valueOf(totalCount));
}
现在的问题是我无法检索数据,因为 res.getString/int
需要列名称/索引,并且从技术上讲,执行此查询时仅返回结果时没有列。
所以我收到此错误:android.database.sqlite.SQLiteException:没有这样的列:二头肌(代码1)
最佳答案
游标公开 SQLiteDatabase 上的查询结果。 不需要列名来获取结果,可以使用索引来获取查询结果。您可以使用案例中的第一个索引来获取计数。
totalCount = res.getInt(0); //this will return the count value
关于android - 无法从使用 count() 的 sqlite 查询中检索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50803549/