android– 如何获取计数列

android– 如何获取计数列,第1张

概述我想从光标中获取Count列的值.publicCursorgetRCount(Stringiplace)throwsSQLException{try{StringstrSql="SELECTCOUNT(_id)ASRCountFROMtbNameWHEREplace='"+iplace+"'";returndb.rawQuery(strSql

我想从光标中获取Count列的值.

public Cursor getRCount(String iplace) throws sqlException{ try {      String strsql = "SELECT COUNT(_ID) AS RCount FROM tbname WHERE place= '" + iplace + "'";                  return db.rawquery(strsql, null);    } catch (sqlException e) {        Log.e("Exception on query", e.toString());        return null;    }} 

我试图从下面的光标获取此计数列

Cursor cR = mDbHelper.getRCount(cplace);if (cR.getCount() > 0){long lCount = cR.getLong(0);}cR.close();}

我收到了调试错误.怎么弄?

PS:我可以使用嵌套游标吗?

解决方法:

您应该使用DatabaseUtils.longForQuery实用程序方法在db上运行查询并返回第一行第一列中的值.

int sometotal=DatabaseUtils.longForquery(db,"SELECT COUNT(_ID) AS RCount FROM tbname WHERE place= '" + iplace + "'",null);
总结

以上是内存溢出为你收集整理的android – 如何获取计数列全部内容,希望文章能够帮你解决android – 如何获取计数列所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115302.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存