java SQLite 计数行 Android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5928338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:29:19  来源:igfitidea点击:

SQLite Count Rows Android

javaandroidsqlite

提问by Somk

I think I have got a script that will work for this, but im struggling to get the value out into a variable and post it into a textview and eventually compare it to another integer.

我想我有一个可以用于此的脚本,但我正在努力将值放入变量并将其发布到文本视图中,并最终将其与另一个整数进行比较。

    private SQLiteDatabase mDatabase;

private long fetchPlacesCount() {
    String sql = "SELECT COUNT(*) FROM " + DB_TABLE;
    SQLiteStatement statement = mDatabase.compileStatement(sql);
    return (int) statement.simpleQueryForLong();

}

回答by lawal

Why don't you use the provided DatabaseUtils class for the query.There is something similary here Android SQLite Cursor out of bounds exception on SELECT count(*) FROM table

为什么不使用提供的 DatabaseUtils 类进行查询。这里有一些类似的东西Android SQLite Cursor out of bounds exception on SELECT count(*) FROM table