I have just recently started working with SQlite database and have ran into a problem. Whenever I try to update or delete data, the app crashes and displays and error "no such column: s_id". I have tried to fix it for days but have had no luck. I would appreciate if someone could tell me what the problem is and why it is occurring. Thank you.
Here is my database:
public class DatabaseHelper extends SQLiteOpenHelper{
public static final String DATABASE_NAME = "sqlite.db";
public static final int VERSION = 1;
public static final String TABLE_NAME = "tbl_reminder";
public static final String S_ID = "s_id";
public static final String S_TITLE = "s_title";
public static final String S_DATE = "s_date";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
S_ID +" TEXT)";
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP_TABLE" + TABLE_NAME);
onCreate(db);
}
public void insertData (String s_title){
ContentValues contentValues = new ContentValues();
contentValues.put(S_TITLE, s_title);
SQLiteDatabase sqLiteDB = this.getWritableDatabase();
sqLiteDB.insert(TABLE_NAME, null, contentValues);
sqLiteDB.close();
}
public ArrayList<ViewHolderHelper> getAllData() {
ArrayList<ViewHolderHelper> list = new ArrayList<>();
String SQL = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(SQL, null);
if (cursor.moveToFirst()) {
do {
ViewHolderHelper vhh = new ViewHolderHelper();
vhh.setiD(cursor.getInt(0) + "");
vhh.setTitle(cursor.getString(1));
list.add(vhh);
} while (cursor.moveToNext());
}
return list;
}
public void updateData(int id, String title){
ContentValues contentValues = new ContentValues();
contentValues.put(S_TITLE, title);
SQLiteDatabase sqliteDB = this.getWritableDatabase();
sqliteDB.update(TABLE_NAME, contentValues, S_ID + "=" + id, null);
sqliteDB.close();
}
public void deleteData(int id){
SQLiteDatabase sqliteDB = this.getWritableDatabase();
sqliteDB.delete(TABLE_NAME, S_ID + "=" + id, null);
sqliteDB.close();
}
}
Here is also the error that is displayed:
FATAL EXCEPTION: main
Process: json.google_services.newreminderapp, PID: 23419
android.database.sqlite.SQLiteException: no such column: s_id (code 1): , while compiling: UPDATE tbl_reminder SET s_title=? WHERE s_id=1