Android SQLite select * from table where name like %key% using prepared statements [duplicate]
if (name.length() != 0) { name = "%" + name + "%"; } if (email.length() != 0) { email = "%" + email + "%"; } if (Phone.length() != 0) { Phone = "%" + Phone + "%"; } String selectQuery = " select * from tbl_Customer where Customer_Name like '" + name + "' or Customer_Email like '" + email + "' or Customer_Phone like '" + Phone + "' ORDER BY Customer_Id DESC"; Cursor cursor = mDb.rawQuery(selectQuery, null);`
Try
Cursor cursor = database.rawQuery(sqlQuery, new String[]{"'%" + criterion + "%'", "'%" + criterion + "%'", "'%" + criterion + "%'", "'%" + criterion + "%'", "'%" + criterion + "%'"});
You are missing the " ' " before and after.
Try like..
String[] a = new String[5];a[0] = '%' + criterion + '%';a[1] = '%' + criterion + '%';a[2] = '%' + criterion + '%';a[3] = '%' + criterion + '%';a[4] = '%' + criterion + '%';Cursor cursor = database.rawQuery(sqlQuery,a);