I got this error:
no such table: form
I am trying to add three fields which are JSON
, JSON_modified
and AdminId
:
static final String DATABASE_NAME = "db1";
static final int DATABASE_VERSION = 2;
public static final int NAME_COLUMN = 1;
static final String DATABASE_TABLE = "create table " + "adminreg" +
"( " + "AdminRegID" + " integer primary key autoincrement," + "Rest_name text,Contact_person_name text,text,PASSWORD text,Address text); ";
// Variable to hold the database instance
static final String DATABASE_TABLE_REG="CREATE TABLE IF NOT EXISTS " + " form " +
"(" + "Id" + " integer primary key autoincrement, " + " JSON text, AdminId text, JSON_modified text);";
public SQLiteDatabase db;
private final Context context;
private DataBaseHelper dbHelper;
public LoginDatabaseAdapter(Context _context)
{
context = _context;
dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LoginDatabaseAdapter open() throws SQLException
{
db = dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String json, String json_modified)
{
Log.e("Data Insert reached", "yes");
ContentValues newValues = new ContentValues();
Log.e("JSON STRING to be insert", json);
newValues.put("JSON", json);
newValues.put("JSON_modified", json_modified);
newValues.put("AdminId", "1");
db.insert("form", null, newValues);
Toast.makeText(context, "Data Is Successfully Saved", Toast.LENGTH_LONG).show();
Log.e("context", "Toast");
}
DataBaseHelper.java
public DataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
{
super(context, name, factory, version);
}
// Called when no database exists in disk and the helper class needs
// to create a new one.
@Override
public void onCreate(SQLiteDatabase _db)
{
_db.execSQL(LoginDatabaseAdapter.DATABASE_TABLE_REG);
_db.execSQL(LoginDatabaseAdapter.DATABASE_TABLE);
}
// Called when there is a database version mismatch meaning that the version
// of the database on disk needs to be upgraded to the current version.
@Override
public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion)
{
// Log the version upgrade.
Log.w("TaskDBAdapter", "Upgrading from version " + _oldVersion + " to " + _newVersion + ", which will destroy all old data");
// Upgrade the existing database to conform to the new version. Multiple
// previous versions can be handled by comparing _oldVersion and _newVersion
// values.
// The simplest case is to drop the old table and create a new one.
_db.execSQL("DROP TABLE IF EXISTS " + "TEMPLATE");
// Create a new one.
onCreate(_db);
}