SQLiteDatabase db = dber.getWritableDatabase();//dber参考上一篇文章
第一种:
db.execSQL("insert into person(name,phone) values(?,?)", new Object[] {p.getName(), p.getPhone() });
db.execSQL("delete from person where personid=?", new Object[] { id });
db.execSQL("update person set name=?,phone=? where personid=?",new Object[] { p.getName(), p.getPhone(), p.getPersonid() });
Cursor cursor = db.rawQuery("select * from person where personid=?",new String[] { id.toString() });
第二种:
ContentValues c=new ContentValues();
c.put("name", p.getName());
c.put("phone", p.getPhone());
SQLiteDatabase db = dber.getWritableDatabase();
//insert(String table, String nullColumnHack, ContentValues values)
db.insert("person", null, c);
db.delete("person", "personid=?", new String[]{id.toString()});
ContentValues c=new ContentValues();
c.put("name", p.getName());
c.put("phone", p.getPhone());
//update(String table, ContentValues values, String whereClause, String[] whereArgs)
db.update("person", c, "personid=?", new String[]{p.getPersonid().toString()});
//query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
db.query("person", null, "personid=?", new String[]{id.toString()}, null, null, null);