公共代码
private SQLiteDatabase database = getWritableDatabase();
1.添加新数据
database.execSQL("insert into "+ tableName + " (_id,name,passName,time) values(?,?,?,?)",
new Object[] {_id,name,passName,time});
2.删除数据,多个条件符号容易迷,只写了多个条件,注意空格
database.execSQL("delete from " + TABLE_NAME_CHAT_RECORD + " where name = '" + name + "'" + "and source = '" + passName +"'" );
3.修改数据,同删除,只列举多个条件,单个条件删除即可
database.execSQL("update " + tableName + " set time= ? , content = ? , source = ?,staues = ? where name = '" + Name + "'",
new Object[] { Time, Content,Source,Staues });
4.查询数据
Cursor cursor = database.rawQuery("select * from " + tableName
+ " where name = ?"+"and source = ?", new String[] { name,source });
#查询的返回对象
while (cursor != null && cursor.moveToNext()) {
}
仅供学习参考