1

I am working on an Android studios project and I have a table that has two columns item and listname.

enter image description here

I want to get all the items that have a common Listname so in this case if I were looking for items that have Market as a listname I only want to get the last 4 from the table, I only want to return the items. I have this but it keeps crashing.

   public Cursor getItem(String listname) {
    SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "SELECT  * FROM " + LIST_ITEM_TABLE + " WHERE "
        + ItemListName + " = " + listname;

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

return c;

}

Yunus UYANIK
  • 1,119
  • 1
  • 10
  • 27
Tony77
  • 21
  • 2

1 Answers1

0

String have to be in single quotes

Also i don't see ItemListName be filled, i hoe there is Listname in it

See like:

String selectQuery = "SELECT  * FROM " + LIST_ITEM_TABLE + " WHERE "
        + ItemListName + " like  '" + listname +"'";
nbk
  • 8,699
  • 6
  • 14
  • 27