Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:19:18+00:00 2026-06-17T07:19:18+00:00

I have a database with all food items. I want to search the database

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:19:19+00:00Added an answer on June 17, 2026 at 7:19 am

    Second argument should not be null… Specify the columns that u need to display..

       return  myDataBase.query( TABLE, new String[] {
                        C_NAME
                        }, 
                        C_NAME + "= ?" , 
                        new String[] { itemName }, ,         
                        null, 
                        null, 
                        null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my MySQL Database all the entries have a rating(an Integer). Now I want
I have a database of items. Each item is categorized with a category ID
Ok, so I have this search box in which people typein a food item.
I have a MYSQL full text search, matching against items in my database, which
I have a food database and I'm trying to implement a simple search that
I have a SQL database with has the following: Customer, Item, Clothing and Food.
We have a database in which all the PKs are GUIDs, and most of
Looking to have a database query set all the instance variables in a class:
I have an existing mongo database where all documents in a collection have a
I have a database with Points of Interest that all have an address. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.