10

My cose is SIMPLE. I have a SQLite-Database with three columns:

  1. rowid
  2. title => text
  3. content => text

This is a method in my dataBase-class:

public Cursor fetchMessage(String tableNane, int id) {
    return myDataBase.rawQuery("SELECT rowid as _id, title FROM "+tableName
    +" WHERE rowid = "+id, null);
}

This method will return only one row.

In my activity I wrote this:

Cursor cursor = myDbHelper.fetchMessage(tableName, id);

Now, I want to store the content field's text in a String.

How can this be done?

1
  • 2
    Don't write with caps lock. It's like shouting around. Commented Jul 10, 2011 at 12:06

2 Answers 2

28

Use this:

if (cursor.moveToFirst()) {
    str = cursor.getString(cursor.getColumnIndex("content"));
}
Sign up to request clarification or add additional context in comments.

Comments

8

First you'll want to move the Cursor you got from your Query to the first row using the moveToFirst()-method.

After that you can get your fields values by using the getString() or getInt()-methods.

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.