开发者

SQl function in android

Cursor cursor = db.rawQuery("SELECT COUNT(rat) 
                               FROM "+ TABLE_NAME_EXTRA +" apkid=\""+apkid, null);
cursor.moveToFirst();
int somatotal = cursor.getInt(0);

I'm trying to do a SQL function like count and sum, but thi开发者_C百科s code returns a exception saying "emptyvalues".

anyone know why?


You should use DatabaseUtils.longForQuery utility method to run the query on the db and return the value in the first column of the first row.

int sometotal=DatabaseUtils.longForQuery(db,"SELECT COUNT(rat) 
                               FROM "+ TABLE_NAME_EXTRA +" where apkid=\""+apkid+"\"",null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜