I have a database with all food items. I want to search the database for a variable food item and get its Cursor. Let us take food item = Oranges as an example. The following line gives the correct result when typed in terminal.
SELECT * from food WHERE item = 'Oranges'
To implement it I made a method called getOneItem in the class which extends SQLiteOpenHelper as below.
public Cursor getOneItem(String itemName) {
return myDataBase.query(TABLE, null, C_NAME+" = " +itemName , null, null, null, null);
}
But when the method is called I get the error “No such column: Oranges, while compiling
SELECT * from table WHERE item = Oranges
Why is the computer searching for a column called Oranges and not searching inside the column for Oranges?
When I modified the method to:
public Cursor getOneItem(String itemName) {
return myDataBase.query(TABLE, null, C_NAME+" = '" +itemName +"'", null, null, null, null);
}
I get CursorIndexOutOfBoundException, Index -1 requested with size of 1
Second argument should not be null… Specify the columns that u need to display..