0

我正在从 sqlite 数据库中获取这样的查询:

String query = "select distinct(" +MessageCountConstant.To_USER + "), sum(" +MessageCountConstant.SEND_MESSAGE_COUNT + ") , "
            + "sum(" +MessageCountConstant.RECIEVE_MESSAGE_COUNT + ") from " +TABLE_NAME + " where " + MessageCountConstant.DATE  + "= " +date
             + " AND "+ MessageCountConstant.DATE  + " >= "+previousDate + " AND "+ MessageCountConstant.JID + " = '"+ Uname + "'"
                        ;


    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    cursor = db.rawQuery(query, null);

现在谁能告诉我如何从光标中获取值。提前谢谢。

4

3 回答 3

1

你可以这样使用它

if (cursor.moveToFirst()){

 do{
      String data = cursor.getString(cursor.getColumnIndex("data");

      // do what ever you want here

   }while(cursor.moveToNext());

}

cursor.close();
于 2013-01-09T13:32:25.817 回答
0

一般来说,您可以通过执行以下操作从光标中获取值:

while( cursor.moveToNext() ) {
    String value1 = cursor.getString(cursor.getColumnIndex("column1"));
    String value2 = cursor.getString(cursor.getColumnIndex("column2"));
}
于 2013-01-09T13:29:29.093 回答
0

您可以像这样获取数据:

for(cursor.move(0);cursor.moveToNext();cursor.isAfterLast()){
   String first = cursor.getString(cursor.getColumnIndex("string_row"));
   int second cursor.getInt(cursor.getColumgnIndex("int_row"));
}

并且不要忘记在获取数据后关闭光标:cursor.close();

于 2013-01-09T13:35:19.260 回答