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

The Archive Base Latest Questions

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

I am working on android project and I need to perform a like query

  • 0

I am working on android project and I need to perform a like query in SQLITE i.e.
SELECT * FROM table WHERE column LIKE %value%.

Below is the code I am using to try and build up the query.

myDB = context.openOrCreateDatabase("PasswordManager", Context.MODE_PRIVATE, null);
            String[] columns = new String[]{"*"};
            if (searchType == SearchType.App)
            {
                where = "appName like ?";
            }
            else if (searchType == SearchType.Username)
            {
                where = "username like ?";
            }
            else if (searchType == SearchType.Name)
            {
                where = "company like ?";
            }

            String[] args = {"%" + searchTerm + "%"};
            cursor = myDB.query("password", columns, where, args, null, null, null);

For some reason this doesn’t return any results if I try and search for a pattere but If I search for the whole string it finds something. For example, if I have the value Hello World and perform a search for Hello, nothing comes back, if I do a search for Hello World then I get a result.

I can’t see why this wouldn’t work. I’ve tried adding and removing the % symbols from around the search term but didn’t make any difference.

Thanks for any help you can provide.

UPDATE
I’ve tried what dymmeh said but this doesn’t seem to have worked. Below is the code I have tried.

myDB = context.openOrCreateDatabase("PasswordManager", Context.MODE_PRIVATE, null);
            String[] columns = new String[]{"*"};
            if (searchType == SearchType.App)
            {
                where = "appName like %" + searchTerm + "%";
            }
            else if (searchType == SearchType.Username)
            {
                where = "username like %" + searchTerm + "%";
            }
            else if (searchType == SearchType.Name)
            {
                where = "company like %" + searchTerm + "%";
            }

            //String[] args = {"%" + searchTerm + "%"};
            cursor = myDB.query("password", columns, where, null, null, null, null);

Using the code above now crashes the app, I’ve tried surrounding the the % searchTerm % in single quote marks, and this stops the app crashing but I get the original problem that if I search for the exact string, a result is found if I search for part of the string, I don’t get any results.

  • 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-15T07:20:19+00:00Added an answer on June 15, 2026 at 7:20 am

    Don’t use the select arguments when using like..

    Instead just do

    where = "appName like '%" + searchTerm + "%'";
    

    And just pass null for your args

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

Sidebar

Related Questions

I am working on my android project with SQLite database. I need to get
I am working on android project. I need to create some fields like the
I am working on an android project and I would like to create an
I am working on an Android project in that i need to send the
I am working on a project where I need to make an Android and
I'm working in a android project the idea is simple: I just need to
I am working on android applications. In my project I need to create Listview.
I'm currently working on debugging some code with my android project. I'm having an
I am working on an android project in which i need to send two
I'm working on an Android project and I need to add buttons to a

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.