如何获得使用SQLite在Android中查询的行数? [英] How to get the row count of a query in Android using SQLite?

查看:176
本文介绍了如何获得使用SQLite在Android中查询的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用SQLite在Android中查询的行数?看来我下面的方法是行不通的。

 公众诠释getFragmentCountByMixId(INT mixId){
    诠释计数= 0;
    SQLiteDatabase DB = dbOpenHelper.getWritableDatabase();

    光标光标= db.rawQuery(
        选择downloadedFragement那里mixId = COUNT(*)?,
        新的String [] {将String.valueOf(mixId)});
    而(cursor.moveToFirst()){
        计数= cursor.getInt(0);
    }
    返回计数;
}
 

解决方案

<一个href="http://developer.android.com/reference/android/database/Cursor.html#getCount%28%29"><$c$c>Cursor.getCount()

How do I get the row count of a query in Android using SQLite? It seems my following method does not work.

public int getFragmentCountByMixId(int mixId) {
    int count = 0;
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase();

    Cursor cursor = db.rawQuery(
        "select count(*) from downloadedFragement where mixId=?",
        new String[]{String.valueOf(mixId)});
    while(cursor.moveToFirst()){
        count = cursor.getInt(0);
    }
    return count;
}    

解决方案

Cursor.getCount()

这篇关于如何获得使用SQLite在Android中查询的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆