Search code examples
javaandroiddatabaselogcat

Simple, how to log (with logcat) a query?


I have this code in eclipse, I'm trying to output all the data from the database table out into a log. How would I log this?

    //---retrieves a particular contact---
public Cursor getTrailer(long rowId) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
            KEY_TITLE, KEY_DESCRIPTION, KEY_RATING}, KEY_ROWID + "=" + rowId, null,
            null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

Solution

  • You need to move into all rows in the cursor. you can try this:

    mCursor.moveToFirst();
    do {
          //print all your columns:
          Log.d("Your class or activity","ID: +"mCursor.getString(c.getColumnIndex("ID"),"ETC:"+mCursor.getString(c.getColumnIndex("ETC"));
    
       } while (mCursor.moveToNext());