Well I created DatabaseHandler class that extends SQLiteOpenHelper. imagine that in this database I save Students Names.It's not important;
there is the code of mainActivity:
public class MainActivity extends AppCompatActivity {
DatabaseHandler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handler = new DatabaseHandler(this);
handler.addStudent(new Student("Aaron"));
handler.addStudent(new Student("David"));
}
}
Then I think: I want a new database for other names,for example for girl students,so I dont need "Aaron" and "David" Any more.So I change code like This:
public class MainActivity extends AppCompatActivity {
DatabaseHandler handlerNew;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handlerNew = new DatabaseHandler(this);
handlerNew.addStudent(new Student("Joan of Arc"));
handlerNew.addStudent(new Student("Suzanne"));
}
}
but when I want to print the names of students from handlerNew,it prints:
Aaron
David
Joan Of Arc
Suzanne
It seems like that old rows are not deleted and new DatabaseHandler hanlerNew has rows of DatabasHandler handler.why? Databases are new for me,I've just started studying.
Aucun commentaire:
Enregistrer un commentaire