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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:31:05+00:00 2026-05-27T09:31:05+00:00

I’m having an issue where I want to create a second table within the

  • 0

I’m having an issue where I want to create a second table within the my database. Here is the code

public class CBDataBaseHelper {

public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "Recipe_Name";
public static final String KEY_CATEGORY = "Recipe_Category";
public static final String KEY_DESCRIPTION = "Recipe_Description";

public static final String KEY_ROWID2 = "_id";
public static final String fKEY_ROWID2 = "f_id";
public static final String KEY_NAME2 = "Ingredient_Name";

private static final String DATABASE_NAME = "Recipedb";
private static final String DATABASE_TABLE = "RecipeData";
private static final String DATABASE_TABLE2 = "IngredientData";
private static final int DATABASE_VERSION = 1;

private DBHelper myHelper;
private final Context mycontext;
private SQLiteDatabase mydatabase;

private static class DBHelper extends SQLiteOpenHelper {
    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db)  {
        // TODO Auto-generated method stub

        db.execSQL("CREATE TABLE " + DATABASE_TABLE + "( " + KEY_ROWID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME
                + " TEXT NOT NULL, " + KEY_CATEGORY + " TEXT NOT NULL,"
                + KEY_DESCRIPTION + " TEXT NOT NULL" + ") ");

        db.execSQL("CREATE TABLE " + DATABASE_TABLE2 + "( " 
        + KEY_ROWID2 + " INTEGER PRIMARY KEY AUTOINCREMENT, "
        + KEY_NAME2 + " TEXT NOT NULL, "  
        + fKEY_ROWID2 + " INTEGER , FOREIGN KEY " + "(" + fKEY_ROWID2 + ") " + "REFERENCES " + DATABASE_TABLE + " ( " +  KEY_ROWID + " ))");

    }





    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

        db.execSQL("DROP IF EXISTS " + DATABASE_TABLE);
        db.execSQL("DROP IF EXISTS " + DATABASE_TABLE2);
        onCreate(db);

    }
}

public CBDataBaseHelper(Context c){
    mycontext = c;

}

public CBDataBaseHelper open() throws SQLException{
    myHelper = new DBHelper(mycontext);
    mydatabase = myHelper.getWritableDatabase();
    return this;
}

public void close(){
    myHelper.close();
}


public long createEntry(String name, String description, String category){

    ContentValues cv = new ContentValues();
    cv.put(KEY_NAME, name);
    cv.put(KEY_CATEGORY, description);
    cv.put(KEY_DESCRIPTION, category);
    return mydatabase.insert(DATABASE_TABLE, null, cv);

}

public long createEntry2(String name){

    ContentValues cv = new ContentValues();
    cv.put(KEY_NAME2, name);
    return mydatabase.insert(DATABASE_TABLE2, null, cv);

}

public Cursor query() {
    // Open Database

    String[] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_CATEGORY, KEY_DESCRIPTION};
    Cursor cursor = mydatabase.query(DATABASE_TABLE, columns, null, null, null, null, null); 
    return cursor;


  }

public Cursor query2() {
    // Open Database

    String[] columns = new String[]{KEY_ROWID2, fKEY_ROWID2, KEY_NAME2};
    Cursor cursor = mydatabase.query(DATABASE_TABLE2, columns, null, null, null, null, null); 
    return cursor;


  }

public Cursor fetchRow(long rowId) throws SQLException {
    Cursor mCursor = mydatabase.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, KEY_NAME,
            KEY_CATEGORY, KEY_DESCRIPTION }, KEY_ROWID + "="
            + rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;

}


 public boolean updateRecipe(long rowId, String RecipeName, 
         String RecipeCategory, String RecipeDescription) 
            {
                ContentValues args = new ContentValues();
                args.put(KEY_NAME, RecipeName);
                args.put(KEY_DESCRIPTION, RecipeDescription);
                args.put(KEY_CATEGORY, RecipeCategory);

                return mydatabase.update(DATABASE_TABLE, args, 
                                 KEY_ROWID + "=" + rowId, null) > 0;
            }
        }

I have a cursor call then to this database for the second table, this is were the error comes in, “no such table”. Any ideas?

  • 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-27T09:31:06+00:00Added an answer on May 27, 2026 at 9:31 am

    Here is the problem, its gonna look bit silly though. The problem is the your onCreate for creating database is not getting called. I am sure but you can confirm that. Also your onUpgrade is not being called. The reason is DB already exists so onCreate won’t gonna call. Now you think onUpgrade will be called but that wont be called as you havn’t changed DATABASE_VERSION.

    Resolution:

    • Remove the database either by command utility ‘adb shell` or via eclipse using the file explorer. The database resides in under ‘/data/data//databases’.

    For adb use rm <db_name>

    Other resolution if some data is already there (that you want to keep for testing), this only for testing purposes:

    • try changing DATABASE_VERSION to something other than what its current value is. This will cause your onUpgrade to be called so write your sqls so that you dont loose data. But obviously your production onUpgrade will be different from this one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.