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);
精彩评论