How To Reset Sqlite Database In Android?
I want my users to be able to reset the application, then I need to reset the SQLite database that I have created. How can I do that? I want to reset the database or delete and re
Solution 1:
Just delete your database by
context.deleteDatabase(DATABASE_NAME);
Please make sure to close your database before deleting.
Solution 2:
Bit late but this can help other people
publicvoidclearDatabase(String TABLE_NAME) {
String clearDBQuery = "DELETE FROM "+TABLE_NAME;
db.execSQL(clearDBQuery);
}
This should remove all the rows from the table refer documentation of SQLite database here!
Solution 3:
Working for me.
@OverridepublicvoidonUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS TABLE_NAME");
onCreate(db);
}
Solution 4:
Just drop tables from database
db.execSQL("DROP TABLE "+TABLENAME);
and again create the table in same database.
Solution 5:
You can delete the content of all your tables using delete from table where 1=1
, or you can call your database onCreate
method again
Post a Comment for "How To Reset Sqlite Database In Android?"