当前位置:首页 > 数据库 > SQlite

如何从sqlite数据库android计算一行表的行

我想在android中计算一个表的行.我使用了两种方法,但没有成功&收到警告信息

Launch timeout has expired, giving up wake lock!
 Activity idle timeout for HistoryRecord{44e26a30 com.india.screen/.CategoryList}

我试过了-

String query="Select count(*) from Holyplace_Tbl";

>使用rawQuery

public void countRows(String query){

Cursor mcursor = assetDatabaseHelper.executeQuery(query);
mcursor.moveToFirst();
int icount = mcursor.getInt(0);
System.out.println("NUMBER IN DB: " + icount);
mcursor.close();

}
>使用DatabaseUtils

public int countRows(String query)
{

   int sometotal = (int) DatabaseUtils.longForQuery(sqliteDatabaseObj, query, null);
  return sometotal;
 }

AssetDatabaseOpenHelper.class

解决方法:

试试这个

private static final String DB_TABLE_PLACES = "Places";
private SQLiteDatabase mDatabase;

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

查看更多Here.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!