SqLite:光标没有正确增加

时间:2016-02-26 05:29:19

标签: java database sqlite

我遇到的问题是我的光标所在的while循环没有运行。 Cursor.columncount()返回适当数量的列。我如何增加光标有错误吗?

Pictoral View(返回列):

|Rating|
|2     |
|3     |
|6     |

函数应返回11/3(3.66666)

public double getAverageRating(String title) {
        title = title.toUpperCase();
        int rating = 0;
        int count = 1;
        SQLiteDatabase db = this.getReadableDatabase();
        String str = "SELECT RATING FROM " + TABLE_NAME + " WHERE TITLE=" + "'" + title + "'" + ";";
        Cursor cur = db.rawQuery(str, null);
        while(cur.moveToNext()) {
            int b = Integer.parseInt(cur.getString(cur.getColumnIndex("RATING")));
            rating += b;
            count++;
        }
        cur.close();
        return (double) rating/count;
        //return rating;
    }

0 个答案:

没有答案