我想在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;
}
解决方法:
试试这个
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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。