"I got error "No Such Table" and cause me to try everything possible to make it gone, now it's gone, but i'm confuse. Here is my situation
I have 2 tables need to create in the apps. and i put one class per table and it's look like code below. If i follow this it will hit me with "No Such Table" when i pull data from "Table2", so i need to change the DATABASE_NAME to some other value = "DB2"; then the "Table2" will create successfully and able to pull out data.
So my question is this a correct way to make sure 2 tables create successfully? or i should not seperate table into 2 classes? Pls advise
public class DB1 extends SQLiteOpenHelper {
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "DB";
// Labels table name
private static final String TABLE_STORE = "Table1";
// Labels Table Columns names
public static final String KEY_1 = "col1";
public RC_StoreTbl(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
// Category table create query
String CREATE_TABLE = "CREATE TABLE " + TABLE_STORE + "("
+KEY_1 + " INTEGER PRIMARY KEY)";
db.execSQL(CREATE_TABLE);
}
}
Another class
public class DB2 extends SQLiteOpenHelper {
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "DB";
// Labels table name
private static final String TABLE_STORE = "Table2";
// Labels Table Columns names
public static final String KEY_1 = "col1";
public RC_StoreTbl(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
// Category table create query
String CREATE_TABLE = "CREATE TABLE " + TABLE_STORE + "("
+KEY_1 + " INTEGER PRIMARY KEY)";
db.execSQL(CREATE_TABLE);
}
}