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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:14:09+00:00 2026-06-09T02:14:09+00:00

i want to use search in my db. so i use several codes that

  • 0

i want to use search in my db. so i use several codes that i will tag them. i use 2 row , one for names and the other for description for name.(something like dictionary). now this is my code and this is my helper for search.
the lines with new comment , i add them to code manually.

public class SQLiteCountryAssistant extends SQLiteOpenHelper
{
private static final String DB_NAME = "usingsqlite.db";
private static final int DB_VERSION_NUMBER = 1;
private static final String DB_TABLE_NAME = "countries";
private static final String DB_COLUMN_1_NAME = "country_name";
private static final String DB_COLUMN_2_DESCRIPTION = "country_description"; //new

private static final String DB_CREATE_SCRIPT = "create table " + DB_TABLE_NAME +
                        " (_id integer primary key autoincrement, " +
                        "country_name text not null);)";

private SQLiteDatabase sqliteDBInstance = null;

public SQLiteCountryAssistant(Context context)
{
    super(context, DB_NAME, null, DB_VERSION_NUMBER);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
    // TODO: Implement onUpgrade
}

@Override
public void onCreate(SQLiteDatabase sqliteDBInstance)
{
    Log.i("onCreate", "Creating the database...");
    sqliteDBInstance.execSQL(DB_CREATE_SCRIPT);
}

public void openDB() throws SQLException
{
    Log.i("openDB", "Checking sqliteDBInstance...");
    if(this.sqliteDBInstance == null)
    {
        Log.i("openDB", "Creating sqliteDBInstance...");
        this.sqliteDBInstance = this.getWritableDatabase();
    }
}

public void closeDB()
{
    if(this.sqliteDBInstance != null)
    {
        if(this.sqliteDBInstance.isOpen())
            this.sqliteDBInstance.close();
    }
}

public long insertCountry(String countryName, String Discription) //new
{
    ContentValues contentValues = new ContentValues();
    contentValues.put(DB_COLUMN_1_NAME, countryName);
    contentValues.put(DB_COLUMN_2_DESCRIPTION, Discription); //new
    Log.i(this.toString() + " - insertCountry", "Inserting: " + countryName);
    Log.i(this.toString() + " - insertDescription", "Inserting: " + Discription); //new
    return this.sqliteDBInstance.insert(DB_TABLE_NAME, null, contentValues);
}

public boolean removeCountry(String countryName)
{
    int result = this.sqliteDBInstance.delete(DB_TABLE_NAME, "country_name='" 
            + countryName + "'", null);

    if(result > 0)
        return true;
    else
        return false;
}

public long updateCountry(String oldCountryName, String newCountryName, String Description)
{ //new
    ContentValues contentValues = new ContentValues();
    contentValues.put(DB_COLUMN_1_NAME, newCountryName);
    contentValues.put(DB_COLUMN_2_DESCRIPTION, Description); //new
    return this.sqliteDBInstance.update(DB_TABLE_NAME, contentValues, "country_name='" 
            + oldCountryName + "'", null);
}

public String[] getAllCountries()
{
    Cursor cursor = this.sqliteDBInstance.query(DB_TABLE_NAME, 
            new String[] {DB_COLUMN_1_NAME}, null, null, null, null, null);

    if(cursor.getCount() >0)
    {
        String[] str = new String[cursor.getCount()];
        int i = 0;

        while (cursor.moveToNext())
        {
             str[i] = cursor.getString(cursor.getColumnIndex(DB_COLUMN_1_NAME));
             i++;
         }
        return str;
    }
    else
    {
        return new String[] {};
    }
}

public String[] getAllDescriptions()
{
    Cursor cursor = this.sqliteDBInstance.query(DB_TABLE_NAME, 
            new String[] {DB_COLUMN_2_DESCRIPTION}, null, null, null, null, null);

    if(cursor.getCount() > 0)
    {
        String[] str = new String[cursor.getCount()];
        int i = 0;

        while (cursor.moveToNext())
        {
             str[i] = cursor.getString(cursor.getColumnIndex(DB_COLUMN_2_DESCRIPTION));
             i++;
         }
        return str;
    }
    else
    {
        return new String[] {};
    }
}

/*** new ***/
public String getDescription(String username) {
    Cursor cursor = this.sqliteDBInstance.query(DB_TABLE_NAME, 
            new String[] {DB_COLUMN_2_DESCRIPTION}, null, null, null, null, null);


    if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
        return null;
    }

    String DES = new String(); 
    DES = cursor.getString(cursor.getColumnIndex(DB_COLUMN_2_DESCRIPTION));
    return DES;
}  
}

in the last function with /*** new ***/, i use search code. i think my problem must be in here…

public class UsingSQLite extends Activity
{
private SQLiteCountryAssistant sqlliteCountryAssistant;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final AutoCompleteTextView textView = (AutoCompleteTextView) 
        findViewById(R.id.autocompleteCountry);

    sqlliteCountryAssistant = new SQLiteCountryAssistant(UsingSQLite.this);
    sqlliteCountryAssistant.openDB();

    // Insert a few countries that begin with "C"
    sqlliteCountryAssistant.insertCountry("Cambodia", "good country");
    sqlliteCountryAssistant.insertCountry("Cameroon", "where is it??");
    sqlliteCountryAssistant.insertCountry("Canada", "i like it :D");
    sqlliteCountryAssistant.insertCountry("Cape Verde", "!!!!!");
    sqlliteCountryAssistant.insertCountry("Cayman Islands", "it must be an island");
    sqlliteCountryAssistant.insertCountry("Chad", "what is that?");
    sqlliteCountryAssistant.insertCountry("Chile", "really, i don't know it!");
    sqlliteCountryAssistant.insertCountry("China", "TOO much big...");

    //sqlliteCountryAssistant.removeCountry("Chad");
    //sqlliteCountryAssistant.updateCountry("Canada", "Costa Rica");

    String[] countries = sqlliteCountryAssistant.getAllCountries();

    // Print out the values to the log
    for(int i = 0; i < countries.length; i++)
    {
        Log.i(this.toString(), countries[i]);
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, 
            countries);

    textView.setAdapter(adapter);
    textView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long rowId) {
            String selection = (String) parent.getItemAtPosition(position);
            TextView tv1 = (TextView) findViewById(R.id.textView1);
            tv1.setText("Description : " + sqlliteCountryAssistant.getDescription(selection));
        }
    });

}

public void onDestroy()
{
    super.onDestroy();
    sqlliteCountryAssistant.close();
}
}

this is my code. i type my word, word appear then i touch it. in this position , i must see the description. but i get error. this is my log cat.

08-04 14:14:26.713: D/dalvikvm(25317): GC_EXTERNAL_ALLOC freed 56K, 52% free 2741K/5639K,      external 264K/519K, paused 79ms
08-04 14:14:28.715: I/Database(25317): sqlite returned: error code = 1, msg = no such column: country_description
08-04 14:14:28.715: D/AndroidRuntime(25317): Shutting down VM
08-04 14:14:28.715: W/dalvikvm(25317): threadid=1: thread exiting with uncaught exception (group=0x401ec560)
08-04 14:14:28.735: E/AndroidRuntime(25317): FATAL EXCEPTION: main
08-04 14:14:28.735: E/AndroidRuntime(25317): android.database.sqlite.SQLiteException: no such column: country_description: , while compiling: SELECT country_description FROM countries
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1235)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1189)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1271)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at com.usingsqlite.SQLiteCountryAssistant.getDescription(SQLiteCountryAssistant.java:140)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at com.usingsqlite.UsingSQLite$1.onItemClick(UsingSQLite.java:61)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:952)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.widget.AutoCompleteTextView.access$1400(AutoCompleteTextView.java:92)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1489)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.widget.ListView.performItemClick(ListView.java:3513)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.os.Handler.handleCallback(Handler.java:587)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.os.Looper.loop(Looper.java:130)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at android.app.ActivityThread.main(ActivityThread.java:3835)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at java.lang.reflect.Method.invokeNative(Native Method)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at java.lang.reflect.Method.invoke(Method.java:507)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-04 14:14:28.735: E/AndroidRuntime(25317):    at dalvik.system.NativeStart.main(Native Method)
08-04 14:14:30.957: I/Process(25317): Sending signal. PID: 25317 SIG: 9

i hope someone can help me.

  • 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-09T02:14:11+00:00Added an answer on June 9, 2026 at 2:14 am

    [1] First of all delete the created database from your AVD

    OR If you have installed it on Real Device, then Uninstall it from device

    because the table already created there has not column DB_COLUMN_2_DESCRIPTION(“country_description”)

    [2] Update your DB_CREATE_SCRIPT as following

    private static final String DB_CREATE_SCRIPT = "CREATE TABLE " + DB_TABLE_NAME
         + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, "
         + DB_COLUMN_1_NAME + " TEXT, "
         + DB_COLUMN_2_DESCRIPTION + " TEXT);";
    

    And then Install and run the whole application from starting activity


    EDIT
    For you bean-class can a java file Countries.java::

    public Countries {
        String name, desc;
    
        public Countries(String name, String desc) {
             this.name = name;
             this.desc = desc;
        }
    }
    

    When you fill cursor read data for both name and description from your database table.

    Then from that fill your

    ArrayList<Countries> countriesList = new ArrayList<Countries>();
    

    using iterator of cursor.

    And when you want to make search data then search it from this filled countriesList.

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

Sidebar

Related Questions

I use codeigniter.I want search in site contents for several word, that did existence
I use regex in Objective-C, I want to search 'a' letter. After several tests,
I want to use the Google Custom Search API (or custom search engine directly)
I want to use Levenshtein algorithm to search in a list of strings. I
I want to use an environment variable in a command with recursive search. export
I want to use Django Haystack with Xapian on my django site for search
I have several strings which look like the following: <some_text> TAG[<some_text>@11.22.33.44] <some_text> I want
I use some libraries that I don't want built as part of every project
I have several classes (A, B, C, ...) that all use a List<AnotherClass> to
I have several views where I want the search bar to be hidden unless

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.