How to perform an SQLite query within an Android application? How to perform an SQLite query within an Android application? sqlite sqlite

How to perform an SQLite query within an Android application?


This will return you the required cursor

Cursor cursor = db.query(TABLE_NAME, new String[] {"_id", "title", "title_raw"},                 "title_raw like " + "'%Smith%'", null, null, null, null);


Alternatively, db.rawQuery(sql, selectionArgs) exists.

Cursor c = db.rawQuery(select, null);


This will also work if the pattern you want to match is a variable.

dbh = new DbHelper(this);SQLiteDatabase db = dbh.getWritableDatabase();Cursor c = db.query(    "TableName",     new String[]{"ColumnName"},     "ColumnName LIKE ?",     new String[]{_data+"%"},     null,     null,     null);while(c.moveToNext()){    // your calculation goes here}