0

i am fetching a query from sqlite database like that :

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);

Now can anyone tell me how can i fetch value from cursor .Thanks in advance.

3 Answers 3

1

you can use it in that way

if (cursor.moveToFirst()){

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

      // do what ever you want here

   }while(cursor.moveToNext());

}

cursor.close();
Sign up to request clarification or add additional context in comments.

Comments

0

Generally speaking, you can get your values from the cursor by doing the following:

while( cursor.moveToNext() ) {
    String value1 = cursor.getString(cursor.getColumnIndex("column1"));
    String value2 = cursor.getString(cursor.getColumnIndex("column2"));
}

Comments

0

You can do fetch data like that :

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

and don't forget to close your cursor after fetching data : cursor.close();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.