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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:45:23+00:00 2026-06-08T00:45:23+00:00

I am trying to search one table for all values in rows with the

  • 0

I am trying to search one table for all values in rows with the same name, and then place them into another table.

I have done this successfully in another part of my application, and have modeled this code after the working code, but for some reason it will not work. It only moves one value from table to table.

I have checked that the table it is taking from, DATABASE_FAV_EQUIP_TABLE, has more than one row in it.

HERE IS THE CODE THAT IS NOT WORKING:

//takes all equip data from saved equip set, and puts into equip table
public String AddSavedEquipToEquipTable(String name) {
        // TODO Auto-generated method stub
        String[] columns = new String[]{KEY_EQUIP, KEY_FAVNAME};
        ContentValues cv = new ContentValues();
        Cursor c = ourDatabase.query(DATABASE_FAV_EQUIP_TABLE, columns, KEY_FAVNAME + "='" + name + "'", null, null, null, null);

        if (c == null){
            return null;
        }
        else if(c != null && c.moveToFirst()) {
            do {
                int iEquip = c.getColumnIndex(KEY_EQUIP);                   

                String equipment = c.getString(iEquip);

                cv.put(KEY_EQUIP, equipment);
                ourDatabase.insert(DATABASE_EQUIP_TABLE, null, cv);

                } while (c.moveToNext() && KEY_FAVNAME == name);
            }


        return null;
    }

HERE IS THE CODE THAT IS WORKING IN ANOTHER PART OF MY APPLICATION:

//takes all rows in chest table and puts them into the chosen equipment database
public String AddToEquipmentDBFromChest(String equip) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{KEY_REPS, KEY_EXERCISE, KEY_TIMETYPE};
    ContentValues cv = new ContentValues();
    Cursor c = ourDatabase.query(DATABASE_CHESTTABLE, columns, KEY_EQUIP + "='" + equip + "'", null, null, null, null);

    if (c == null){
        return null;
    }
    else if(c != null && c.moveToFirst()) {
        do {
            int iReps = c.getColumnIndex(KEY_REPS);
            int iExercise = c.getColumnIndex(KEY_EXERCISE);
            int iTimeType = c.getColumnIndex(KEY_TIMETYPE);

            String reps = c.getString(iReps);
            String exercise = c.getString(iExercise);
            String time = c.getString(iTimeType);

            cv.put(KEY_REPS, reps);
            cv.put(KEY_EXERCISE, exercise); 
            cv.put(KEY_TIMETYPE, time);

            ourDatabase.insert(DATABASE_CHOSEN_EQUIP_TABLE, null, cv);
            } while (c.moveToNext() && KEY_EQUIP == equip);
        }


    return null;
}

I have gone over this again and again and I have to be missing something.

  • 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-08T00:45:25+00:00Added an answer on June 8, 2026 at 12:45 am

    Neither KEY_FAVNAME or name change inside your function, so comparing them on each iteration of your loop is not going to do anything useful. Given that you’re already checking for matching names in the query, I can’t see why you are trying to do this check in your loop as well. Just take out the KEY_FAVNAME == name comparison altogether.


    Incidentally:

    KEY_FAVNAME == name
    

    This is not how you compare strings in Java. This is better:

    KEY_FAVNAME.equals(name)
    

    Even more incidentally: your code is needlessly verbose. You don’t need to null-check the cursor, as an exception will be thrown if the query fails. You do, however, need to close the cursor once you’re finished. A typical pattern is this:

    Cursor c = db.query(....);
    try {
    
        // do all your cursor iteration in here
    
    } finally {
        c.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to search for information in one table (DATABASE_FAV_EQUIP_TABLE) based on a
I am trying to do a search in one directory containing a large number
Im trying to search two of the fields in my table. (Database table contains
I'm trying to search through many documents and find all instances where an html
I am trying to dynamically filter table cell contents according to a search box.
I have a table with a one to many mapping to a table that
I have a simple MySQL query that selects all columns from the table based
I am trying to build an easy search based on 2 MySQL tables. One
I have a SQL Server table and I'm trying to make sense of fulltext
The following query works properly to pull company names from one table into jquery

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.