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;
  • The query itself appears mostly fine, the only part I find a little odd is your WHERE statement putting the value on the left and the column name on the right of the equal sign, so you might want to flip those around. Outside of that I'm not sure what programming language you're using to execute the SQL code...C#? My guess is the issue you're experiencing is on that end of things.
    – J.D.
    Nov 7, 2020 at 23:59

1 Answer 1


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 +"'";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.