I am writing application which uses SQLite. At first, my database had only one table called `products`. Now I want to add one more table called `favouriteproduct_table`. I wrote `db.exec("create table fav_product")` command in the `onCreate` method, but my app is crashing saying that no table found for `Product_fav`.
This is my code before adding favourite_product_table.
private static class OpenHelper extends SQLiteOpenHelper
{
OpenHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, systemSerID TEXT, systemSerName TEXT, productID TEXT, productName TEXT, productDesc TEXT, productType TEXT, batchID TEXT, minVal TEXT, maxVal TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w("Example", "Upgrading database, this will drop tables and recreate.");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
Above code is working fine, but when I try to create a new table using the following code, my app crashes.
private static class OpenHelper extends SQLiteOpenHelper
{
OpenHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, systemSerID TEXT, systemSerName TEXT, productID TEXT, productName TEXT, productDesc TEXT, productType TEXT, batchID TEXT, minVal TEXT, maxVal TEXT)");
db.execSQL("CREATE TABLE " + TABLE_TOPUP_FAVOURITE + "(id INTEGER PRIMARY KEY, systemSerID TEXT, systemSerName TEXT, productID TEXT, productName TEXT, productDesc TEXT, productType TEXT, batchID TEXT, minVal TEXT, maxVal TEXT, imageid TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w("Example", "Upgrading database, this will drop tables and recreate.");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}