`

sqlite数据库对于插入大数据的时候采用事务处理会大大减少插入时间一万条数据三秒插入完成

 
阅读更多

1   定义要插入的数据  从服务器获取的json字符串

 

//str3为从服务器获取的json字符串数据
			 if (str3 != null) {
				 //定义SQlite数据库 ,获取实例化引用
			 db = dbhelper.getWritableDatabase();
			 //开启一个事务。如果不提交事务就会自动滚动处理
			 db.beginTransaction();
			 //将json字符串数据转换成List字符串
			 tcc58Arr = JSON.parseArray(str3,
			 TCC58Paste.class);
			 try {
			 for (int i = 0; i < tcc58Arr.size(); i++) {
				 //将List字符串数据转化成实体对象TCC58Paste
			 TCC58Paste t_cc58Paste=tcc58Arr.get(i);
			   //回滚插入数据
			 db.execSQL(
			 "insert into t_cc58manage(cc58_no, goods_info_id, upper_cc55_no , cc_past_date, "
			 +
			 "cc58_father_no, is_father, cc_status, trace_description, cc_error, sys_kbn, "
			 +
			 "company_id, store_id, terminal_id, charger_id, send_date, ins_user, ins_charger, "
			 +
			 "ins_date, upd_user, upt_charger, upd_date) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
			 // 18/18
			 new Object[] { t_cc58Paste.getCc58NO(),
			 t_cc58Paste.getGoodsInfoId(),
			 t_cc58Paste.getUpperCc55No(),
			 t_cc58Paste.getCcPastDate(),
			 t_cc58Paste.getCc58_father_no(),
			 t_cc58Paste.getIs_father(), t_cc58Paste.getCcStatus(),
			 t_cc58Paste.getTraceDescription(),
			 t_cc58Paste.getCcError(), t_cc58Paste.getSysKbn(),
			 t_cc58Paste.getCompanyId(), t_cc58Paste.getStoreId(),
			 t_cc58Paste.getTerminalId(),
			 t_cc58Paste.getChargerId(), t_cc58Paste.getSendDate(),
			 t_cc58Paste.getInsUser(), t_cc58Paste.getInsCharger(),
			 t_cc58Paste.getInsDate(), t_cc58Paste.getUpdUser(),
			 t_cc58Paste.getUptCharger(), t_cc58Paste.getUpdDate() });
			 }
			//提交事务处理
			 db.setTransactionSuccessful();
			 }finally {
			 // TODO Auto-generated catch block
				 //结束事务处理
			 db.endTransaction();
			 }
			
			 }

  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics