I am working on the SQLite database and i want to clear DB after fetching data from it. Kindly guide me on how can I clear/empty DB after fetching data from it.
Asked
Active
Viewed 40 times
-1
-
You can delete all tables,views from database after fetching data or try this context.deleteDatabase(DATABASE_NAME); – niceumang Mar 05 '20 at 11:33
1 Answers
1
There are two option to clear the table from the database
Firstly
If you wan to delete the data on specific row you need to add this code in the database class
public boolean deleteSpecificOrder(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");
Secondly
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;
db.execSQL(clearDBQuery);
}
and then add the below line where you want to perform that action
db.clearDatabase("table_food_items");
I Hope that will help you

Muhammad Yaseen
- 278
- 2
- 12