Skip to content
Advertisement

I can’t create sqlite multiple tables android where did my code go wrong?

I want to create a 2 sqlite table but second table can’t be created just frist table was created. I don’t know where code go wrong.

this is my code to create

    public static final String FOOD_TABLE = "FOOD_TABLE";
    public static final String ADDED_TABLE = "ADDED_TABLE";
    public static final String COLUMN_FOOD_NAME = "FOOD_NAME";
    public static final String COLUMN_FOOD_CAL = "FOOD_CAL";
    public static final String COLUMN_FOOD_SODIUM = "FOOD_SODIUM";
    public static final String COLUMN_FOOD_SUGAR = "FOOD_SUGAR";
    public static final String COLUMN_ID = "ID";

    @Override
    public void onCreate(SQLiteDatabase db) {
        String createTableStatement = "CREATE TABLE " + FOOD_TABLE + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_FOOD_NAME + " TEXT, " + COLUMN_FOOD_CAL + " INT, " + COLUMN_FOOD_SODIUM + " INT, " + COLUMN_FOOD_SUGAR + " INT)";
        String createTableStatement1 = "CREATE TABLE " + ADDED_TABLE + " (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_FOOD_NAME + " TEXT, " + COLUMN_FOOD_CAL + " INT, " + COLUMN_FOOD_SODIUM + " INT, " + COLUMN_FOOD_SUGAR + " INT)";
        db.execSQL(createTableStatement);
        db.execSQL(createTableStatement1);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("DROP TABLE IF EXISTS " +FOOD_TABLE);
        db.execSQL("DROP TABLE IF EXISTS " +ADDED_TABLE);
        onCreate(db);
    }

Advertisement

Answer

I already solved it!,i just reinstall app

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement