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

  • Home
  • SEARCH
  • 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 8454107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:56:17+00:00 2026-06-10T11:56:17+00:00

Im a noob to android and I am trying to run a query on

  • 0

Im a noob to android and I am trying to run a query on my database to return a single string value from my table. I have done this successfully in one query by selecting my row id using a long. Shown here:

public String getHotness(long l) throws SQLException{
    // TODO Auto-generated method stub
    String[] columns = new String[]{  KEY_ROWID, KEY_NAME, KEY_HOTNESS };
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null);
    if (c != null){
        c.moveToFirst();
        String hotness = c.getString(2);
        return hotness;
    }
    c.close();
    return null;
}

But now i have to query another table using a string, but when i execute this query i get a SQLException.

public String getSingleQty(String aCoin) throws SQLException{
    // TODO Auto-generated method stub
    String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_QUANTITY, KEY_OUNCES, KEY_VALUE};     
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + "=" + aCoin, null, null, null, null); //<--this causes exception
    String result = "";

    if (c != null){
        c.moveToFirst();
        result= c.getString(2);
        c.close();
        return result;
    }
    c.close();
    return null;

I don’t understand why this is occurring. I used the same format for both tables. Any help is greatly appreciated.

  • 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-10T11:56:18+00:00Added an answer on June 10, 2026 at 11:56 am

    Since aCoin is being passed as a string to the query, it has to be wrapped by apostrophes. Corrected fragment of code:

    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + "='" + aCoin + "'", null, null, null, null);
    

    or (if the syntax suit you better) try it that way:

    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + "=?", new String[] {aCoin}, null, null, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a noob to android and im am trying to query a sqlite table.
Im an Android noob, coming from objC, I have a very stupid question (project
This is an Android noob question. I am trying to start an activity of
have been away from Android for more than a year, trying to pick up
I am a complete Android and C in general noob, I have done a
android noob... I have two tables, with a one to many relationship between country_tbl
I am trying to get a stringArray resource with this code: String continent =
I am trying to write some variable data back to a database table when
i have to show some operations in Android,,, but Im having some noob problem,
Okay, first, I'm a noob at android programming. I have taken some Java, but

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.