区别与网上的数据库备份恢复:使用内存集合list或者map

网上流传较多的是:数据库文件的备份存储和文件还原 :也就是数据库操作之前保存一份原来的文件 需要还原的时候 用这份文件替换操作了的数据库文件

但是对于条数有限制的数据库 表格 需要还原:只需要保存原来的一份数据库表中的 数据 需要还原的时候 还原回来就可以了

但是 不能使用下列的方法

从数据库表中取出全部数据 放到一个集合1中 然后 new 一个新集合2 2.addall(1)
//特别注意:集合中保存的是对象的地址引用:操作1 改变了 同时2中相同对象也发生改变:所以就不再具备使用2来还原的功能

所以上述方法是错误的

那么:实际是

在遍历数据库表 得到cursor的时候:new对象的时候 new 两个对象 一个网 集合1中存 一个往集合2中存 改变中改变 集合1 集合2为恢复数据库表做准备

//获取数据库的集合
Cursor cursor= App.getSqlManager().seleteAll(tableName,new String[]{“id”,”name”,”mobile”,”identitycard”,”agent”},”id desc”);
if (cursor!=null&&cursor.getCount()>0){
Log.e(“jxf”, “customer数据库有数据”);
while(cursor.moveToNext()) {
BuyTicketInfo bean=new BuyTicketInfo();
BuyTicketInfo bean1=new BuyTicketInfo();
bean.id=cursor.getInt(0);
bean1.id=cursor.getInt(0);
bean.name=cursor.getString(1);
bean1.name=cursor.getString(1);
bean.mobile=cursor.getString(2);
bean1.mobile=cursor.getString(2);
bean.identityCard=cursor.getString(3);
bean1.identityCard=cursor.getString(3);
bean.agent=cursor.getString(4);
bean1.agent=cursor.getString(4);
//默认的勾选框是不勾选的
bean.isCheck=false;
//1 新学员 2 复训
bean.identify=1;
sqlCustomers.add(bean);
tempBackUpSql.add(bean1);
}
cursor.close();
// if (sqlCustomers.size()>40){
// int id=sqlCustomers.get(39).id;
// App.getSqlManager().deleteOne(tableName, “id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值