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 3227494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:34:52+00:00 2026-05-17T16:34:52+00:00

I am trying to query a string (TEXT field in the database) and want

  • 0

I am trying to query a string (TEXT field in the database) and want to fetch records based on that query. I was following a tutorial which works fine if I query an Integer (the _ID field). What will I need to change in the code below to let it search for the string (the TEXT field) instead of the _ID field?

The activity code:

protected void getDetails() {
    try
    {
        // The ArrayList that holds the row data
        ArrayList<Object> row;
        // ask the database manager to retrieve the row with the given rowID
        row = db.getRowAsArray(Long.parseLong(txtProjContacts.getText().toString()));

        // update the form fields to hold the retrieved data
        txtName.setText((String)row.get(1));
        txtEmail.setText((String)row.get(2));
        txtExpertise.setText((String)row.get(3));
        txtCharges.setText((String)row.get(4));
    }
    catch (Exception e)
    {
        Log.e("Retrieve Error", e.toString());
        e.printStackTrace();
    }

}

The DB Adapter code:

public ArrayList<Object> getRowAsArray(Long rowID)
{
    // create an array list to store data from the database row.
    // I would recommend creating a JavaBean compliant object 
    // to store this data instead.  That way you can ensure
    // data types are correct.
    ArrayList<Object> rowArray = new ArrayList<Object>();
    Cursor cursor;

    try
    {
        // this is a database call that creates a "cursor" object.
        // the cursor object store the information collected from the
        // database and is used to iterate through the data.
        cursor = db.query
        (
                TABLE_CONTACTS,
                new String[] {     TABLE_CON_ID,
                                TABLE_CON_NAME,
                                TABLE_CON_EMAIL,
                                TABLE_CON_EXPERTISE,
                                TABLE_CON_CHARGES},
                TABLE_CON_ID + "=" + rowID,
                null, null, null, null, null
        );

        // move the pointer to position zero in the cursor.
        cursor.moveToFirst();

        // if there is data available after the cursor's pointer, add
        // it to the ArrayList that will be returned by the method.
        if (!cursor.isAfterLast())
        {
            do
            {
                rowArray.add(cursor.getLong(0));
                rowArray.add(cursor.getString(1));
                rowArray.add(cursor.getString(2));
                rowArray.add(cursor.getString(3));
                rowArray.add(cursor.getString(4));
            }
            while (cursor.moveToNext());
        }

        // let java know that you are through with the cursor.
        cursor.close();
    }
    catch (SQLException e) 
    {
        Log.e("DB ERROR", e.toString());
        e.printStackTrace();
    }

    // return the ArrayList containing the given row from the database.
    return rowArray;
}

Thanks in advance.

  • 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-05-17T16:34:53+00:00Added an answer on May 17, 2026 at 4:34 pm

    You’ll need to make sure you’re select condition is such that it’s enclosed within quotes.

    Untested Code

    cursor = db.query
            (
                    TABLE_CONTACTS,
                    new String[] {     TABLE_CON_ID,
                                    TABLE_CON_NAME,
                                    TABLE_CON_EMAIL,
                                    TABLE_CON_EXPERTISE,
                                    TABLE_CON_CHARGES},
                    TABLE_CON_NAME + "= \"" + name_to_be_searched + "\"",
                    null, null, null, null, null
            );
    

    But this leads to the Possibility of SQL Injection so use SQLLiteQuery

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying write a query to find records which don't have a matching record
I'm trying out the following query: SELECT A,B,C FROM table WHERE field LIKE 'query%'
I'm trying to write a query that will pull back the two most recent
Before trying to query the AD server I would like to check if it
I'm trying to do query result pagination with hibernate and displaytag, and Hibernate DetachedCriteria
I'm trying to optimize query performance and have had to resort to using optimizer
When trying to enter a SQL query with parameters using the Oracle OLE DB
I' trying to use a Linq query to find and set the selected value
I'm trying to perform a LINQ query on a DataTable object and bizarrely I
I'm trying to perform a SQL query through a linked SSAS server. The initial

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.