SQLiteDatabase db = ....;
Cursor cursor = db.rawQuery("“select count(*) from tableA", null);
while (cursor.moveToNext()) {
int personid = cursor.getInt(0); //获取第一列的值,第一列的索引从0开始
String name = cursor.getString(1);//获取第二列的值
int age = cursor.getInt(2);//获取第三列的值
Cursor cursor = db.rawQuery("“select count(*) from tableA", null);
while (cursor.moveToNext()) {
int personid = cursor.getInt(0); //获取第一列的值,第一列的索引从0开始
String name = cursor.getString(1);//获取第二列的值
int age = cursor.getInt(2);//获取第三列的值
为什么要用游标?
我用的是CppSQLite3DB类,里面execScalar函数直接返回记录数的
2. 1是代表着返回一条数据,而不是count(*)的值RecNo count(*)
1 0 只有这1条数据
奇怪,这个问题困扰我半天了,愣是没明白什么原因补充说明一下,有数据的情况下,返回值是正确的,用count(*)
比如我有3条数据,则返回的确实是 intCount = 3
一条数据返回的是 intCount = 1可就是为什么没数据的时候也返回的是 intCount = 1 ?? 这就有点纳闷了