I have the following code that creates my table. I insert data into it that looks like this
_id date recordName total
--------------------------
You need to put single quotes around the value, otherwise it will treat it as a column.
KEY_RECORD_NAME + " = '" + name + "'"
Note: This solution is open to Sql Injection, you should use parameter placeholders, and pass the values via the selectionArgs
argument:
public Cursor getRecord(String name) throws SQLException {
return mDb.query(true,
DATABASE_TABLE_RECORDS,
new String[] {KEY_ROWID, KEY_DATE, KEY_RECORD_NAME, KEY_TOTAL},
KEY_RECORD_NAME + " = ?",
new String[] {name},
null, null, null, null);
}
Alternatively, look into SQLiteQueryBuilder