一共有30个参数,写起来有点费劲,有啥其它方法实现批量更新吗?
#sql("batchsavealarm") merge into se_alarm_info t1 using dual on (t1.clearkeyword = ?) when matched then update SET CLEARED = ?, RAISETIME = ?, CLEARTIME = ?, OPERTIME = ? where clearkeyword = ? and cleared !='true' when not matched then insert (ID, SWITCH, STATIONTYPE, CLEARKEYWORD, CLEARED, EMSALARMID, ALARMTEXT, CAUSE, SOURCE, SOURCETYPE, RAISETIME, CLEARTIME, LEVELS, NETYPE, WBJ, EQUIPNAME, VENDORID, EMSID, LON, LAT, OMCALARMID, FAULTBILLRULE, OPERTIME, hid) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SEQ_se_alarm_info.Nextval) #end
public void saveAlarm(String filePath) { String sql = "clearkeyword,cleared,raisetime,cleartime,opertime,clearkeyword,id,switch,stationtype,clearkeyword,cleared,emsalarmid,alarmtext,cause,source,sourcetype,raisetime,cleartime,alarmlevel,netype,wbj,equipname,vendorid,emsid,lon,lat,omcalarmid,faultbillrule,opertime"; try { // 创建CSV读对象 CsvReader csvReader = new CsvReader(filePath, ',', Charset.forName("gbk")); csvReader.readHeaders(); // 跳过表头 如果需要表头的话,不要写这句。 String[] head = csvReader.getHeaders(); // 获取表头 List<Record> alarmlist = new ArrayList<Record>(); while (csvReader.readRecord()) { Record alarm = new Record(); // Map<String, Object> para = new HashMap<String, Object>(); for (int i = 0; i < head.length; i++) { if ("alarmlevel".equals(head[i].toLowerCase())) { alarm.set("levels", csvReader.get(head[i])); } else { alarm.set(head[i].toLowerCase(), csvReader.get(head[i])); } } alarm.set("id", UUIDUtil.getUUID()); alarm.set("opertime", DateUtil.getDateTime()); alarmlist.add(alarm); // Db.update(Db.getSqlPara("alarm.savealarm", para)); } Db.batch(Db.getSql("alarm.batchsavealarm"), sql, alarmlist, 5000); } catch (IOException e) { e.printStackTrace(); } try { TimeUnit.HOURS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } this.stop(); }
项目:JFinal
然后再使用 Db.batch 带有一条 sql 以及多行参数的方法即可