Reputation: 1636
I'm new to the sqlite
database in android. I'm using eclipce
adt-bundle
and its simulator. In my project, I have a sqlite
database. I need to clear data in each run of this application. Otherwise I always get the same sqlite exception again and again. So how can I clear database data in the simulator in each run?
Upvotes: 0
Views: 145
Reputation: 1617
Using this code, you can clear all or some specific tables. In you SQLiteOpenHelper Class :
public void deleteAllTable() {
db.execSQL("DELETE FROM " + TABLE_NAME_ONE);
db.execSQL("DELETE FROM " + TABLE_NAME_TWO);
db.execSQL("DELETE FROM " + TABLE_NAME_THREE);
}
In Your Launcher activity's onCreate :
DBAdapter db = new DBAdapter (context,DBAdapter.DATABASE_NAME);
db.deleteDARtable();
db.close();
Upvotes: -1
Reputation: 4306
In the case, you want to delete whole SQLite database from your app.
public class MyActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
getApplicationContext().deleteDatabase(YOUR_DATABASE_NAME);
}
}
Upvotes: 2