How to reset SqLite database in Android?-ThrowExceptions

Exception or error:

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 recreate the database.

How to solve:

Just delete your database by


Please make sure to close your database before deleting.


Bit late but this can help other people

public void clearDatabase(String TABLE_NAME) {  
   String clearDBQuery = "DELETE FROM "+TABLE_NAME;  

This should remove all the rows from the table refer documentation of SQLite database here!


Working for me.

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {


Just drop tables from database


and again create the table in same database.


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


There are two option to clear the table from the database


If you wan to delete the data on specific row you need to add this code in the database class

    public Boolean specification(int id, String table_name)
         return db.delete(table_name, KEY_ID + "=" + id, null) > 0;

and add the below code when you want to perform this action

  db.deleteSpecificOrder(id, "table_orders");


If you want to delete all the data from th table then you just need to add below code into your database

public void clearDatabase(String TABLE_NAME) {
    db = this.getReadableDatabase();
    String clearDBQuery = "DELETE FROM " + TABLE_NAME;

and then add the below line where you want to perform that action


I Hope that will help you

Leave a Reply

Your email address will not be published. Required fields are marked *