SQLite 统计行数 Android
我想我有一个可以解决这个问题的脚本,但是我正在努力将值放入变量中并将其发布到文本视图中并最终将其与另一个整数进行比较。
private SQLiteDatabase mDatabase;
private long fetchPlacesCount() {
String sql = "SELECT COUNT(*) FROM " + DB_TABLE;
SQLiteStatement statement = mDatabase.compileStatement(sql);
return (int) statement.simpleQueryForLong();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不使用提供的 DatabaseUtils 类进行查询。这里有类似的东西 Android SQLite 游标越界异常 SELECT count(*) FROM table
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