public void add() {
MyHelPer helPer = new MyHelPer(getContext());
SQLiteDatabase db = helPer.getReadableDatabase();
for (int i = 0; i < 10; i++) {
db.execSQL("insert into student values(null,'张三',18" + i + ")");
}
}
public void remove() {
MyHelPer helPer = new MyHelPer(getContext());
SQLiteDatabase db = helPer.getReadableDatabase();
db.execSQL("delete from student where id = 1");
}
public void update() {
MyHelPer helPer = new MyHelPer(getContext());
SQLiteDatabase db = helPer.getReadableDatabase();
db.execSQL("update student set name = '李四'");
}
public void query() {
MyHelPer helPer = new MyHelPer(getContext());
SQLiteDatabase db = helPer.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from student ", null);
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex("id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
String age = cursor.getString(cursor.getColumnIndex("age"));
String nick = cursor.getString(cursor.getColumnIndex("nick"));
System.out.println("id = "+id +" name = "+name + " age = "+age +" nick = "+nick);
}
}