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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:29:01+00:00 2026-06-06T17:29:01+00:00

I am trying to search for information in one table (DATABASE_FAV_EQUIP_TABLE) based on a

  • 0

I am trying to search for information in one table (DATABASE_FAV_EQUIP_TABLE) based on a value, pull that information, and then place it into another table (DATABASE_EQUIP_TABLE) – checking first if it is not already there. My code is below. Nothing is crashing, and I am not getting any errors, however no information gets placed into the second table (DATABASE_EQUIP_TABLE). I have gone over it several times and cannot figure out why this isn’t working.

//takes all equip data from saved equip set, and puts into equip table
public String AddSavedEquipToEquipTable(String name) {

    String[] columns = new String[]{KEY_EQUIP};
    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 equip = c.getString(iEquip);

            CheckEquipTable(equip);

            c.moveToNext();

            } while (KEY_FAVNAME == name);
        }

    return null;
}


public void CheckEquipTable(String equip){

    String[] columns = new String[]{KEY_EQUIP};
    ContentValues cv = new ContentValues();
    Cursor check = ourDatabase.query(DATABASE_EQUIP_TABLE, columns, KEY_EQUIP + "='" + equip + "'", null, null, null, null);

    if(check == null){              
        cv.put(KEY_EQUIP, equip);
        ourDatabase.insert(DATABASE_EQUIP_TABLE, null, cv);
        }

}
  • 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-06T17:29:02+00:00Added an answer on June 6, 2026 at 5:29 pm

    Try this:

    public void AddSavedEquipToEquipTable(String name) {
        String[] columns = new String[]{KEY_EQUIP};
        Cursor c = ourDatabase.query(DATABASE_FAV_EQUIP_TABLE, columns, KEY_FAVNAME + "='" + name + "'", null, null, null, null);
    
        int iEquip = c.getColumnIndex(KEY_EQUIP);
        while(c.moveToNext())
            CheckEquipTable(c.getString(iEquip));
    }
    

    I’ll explain a few changes:

    • The column index of KEY_EQUIP will not change so we only need to retrieve the index once
    • In Java you must compare Strings with if(name.equals(KEY_FAVNAME)) not ==, (KEY_FAVNAME == name) is probably false.
    • ourDatabase.query() will never return null, the smallest result will be an empty Cursor (as in cursor.getCount() == 0)
    • cursor.moveToNext() returns true / false, and when the index is at -1 moveToNext() is the same as moveToFirst(). Also if the Cursor is empty then moveToNext() returns false.

    Don’t hesitate with any other questions with my suggestion. Hope that helps!

    Addition

    I didn’t notice CheckEquipTable() was checking if a Cursor is null the first time:

    if(check == null){
    

    Change it like so:

    if(check.getCount() == 0){              
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a CSS-based table that will be populated with information coming
I am trying to have PHP search based on letters entered into a text
I've been trying to find some manual information on this, but my search is
Im trying to search two of the fields in my table. (Database table contains
We're a couple of students trying to implement a design to search for customer-information
I am trying to provide useful information on an area to users based on
I have one ' Log ' entity which contains information about temperature. I'm trying
I'm trying to write an Android app that will allow a user to search
I'm trying to make an app where a user inputs some information and then
While trying to search with id sorting (and paginating) im getting from the log:

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.