Retrieving data from SQLite databases in Android is done using cursors. The SQL method SQLite query returns a Cursor object containing the query results. To use cursors android.database.Cursor needs to be imported.
To get all column values
try it
DatabaseHelper mDbHelper = new DatabaseHelper(getApplicationContext());
SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
Cursor cursor = mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME,
KEY_DESIGNATION}, null, null, null, null, null);
To get column data
Try it,
Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_NAME, KEY_DESIGNATION}, KEY_ROWID + "=" + yourPrimaryKey, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
After getting the cursor, you can just iterate over the values, for example
cur.moveToFirst();
while (cur.isAfterLast() == false) {
cur.getString(colIndex);
cur.moveToNext();
}
cur.close();
, .