区别与网上的数据库备份恢复:使用内存集合list或者map
2016-03-16 18:14
357 查看
网上流传较多的是:数据库文件的备份存储和文件还原 :也就是数据库操作之前保存一份原来的文件 需要还原的时候 用这份文件替换操作了的数据库文件
但是对于条数有限制的数据库 表格 需要还原:只需要保存原来的一份数据库表中的 数据 需要还原的时候 还原回来就可以了
但是 不能使用下列的方法
从数据库表中取出全部数据 放到一个集合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
但是对于条数有限制的数据库 表格 需要还原:只需要保存原来的一份数据库表中的 数据 需要还原的时候 还原回来就可以了
但是 不能使用下列的方法
从数据库表中取出全部数据 放到一个集合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
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- 数据库链接字符串查询网站
- 我是运营,我没有假期
- DB2实例管理
- DB2实例管理
- 保障MySQL数据安全的14个最佳方法
- mysql问答汇集
- Tomcat端口被占用解决方法(不用重启)
- 第三章 数据库备份和还原
- 创建一个空的IBM DB2 ECO数据库的方法
- 路由器备份配置
- Access 2000 数据库 80 万记录通用快速分页类
- IE7降低内存和降低CPU的几个技巧
- 开通一个数据库失败的原因的和解决办法
- 一个简单的asp数据库操作类
- DB2数据库的安装
- C#实现把指定数据写入串口
- CentOS下DB2数据库安装过程详解
- “传奇”图象数据存储方式