sql中批量插入begin的使用

 1     private static String ADD_ATTR_EXT_ITEM="insert into attr_ext_item(attr_ext_main_key,attr_name_key,attr_type,data_type,mode,
                             tolerance,target_value,attr_lower_value,attr_higher_value,fetch_attr_group,
fetch_attr_name,calc_expression,serial_port,serial_port_baud_rate,serial_port_data_format,
pages)"; 2 public boolean saveAttrExtItem(final List<AttrExtItem> listAttrExtItem,final int attrExtMainid) { 3 boolean result = true; 4 if (listAttrExtItem == null || listAttrExtItem.size() == 0) 5 return false; 6 StringBuffer buffer = new StringBuffer(); 7 try { 8 buffer.append("begin;" ); 9 for (int i = 0; i < listAttrExtItem.size(); i++) { 10 AttrExtItem att = listAttrExtItem.get(i); 11 buffer.append(ADD_ATTR_EXT_ITEM); 12 buffer.append(" values(" 13 +attrExtMainid 14 + ", " + att.getAttrNameKey() 15 + ", '" + att.getAttrType() 16 + "', '" + att.getDataType() 17 + "', '" + att.getMode() 18 + "', '" + att.getTolernace() 19 + "', '" + att.getTargetValue() 20 + "', '" + att.getAttrLowerValue() 21 + "', '" + att.getAttrHigherValue() 22 + "','" + att.getFetchAttrGroup() 23 + "', '" + att.getFetchAttrName() 24 + "', '" + att.getCalcExpression() 25 + "', '" + att.getSerialPort() 26 + "', " + att.getSerialPortbAUDRate() 27 + ", '" + att.getSerialPortDataFormat() 28 + "', '" + att.getPages() 29 +"'"+ ");"); 30 } 31 buffer.append("commit;"); 32 log.info("Add AttrExtItem sql: " + buffer.toString()); 33 this.getJdbcTemplate2().update(buffer.toString()); 34 } catch (Exception e) { 35 result = false; 36 log.error(e); 37 } 38 return result; 39 }

 

private static String ADD_ATTR_EXT_ITEM="insert into attr_ext_item(attr_ext_main_key,attr_name_key,attr_type,data_type,mode,tolerance,target_value,attr_lower_value,attr_higher_value,fetch_attr_group,fetch_attr_name,calc_expression,serial_port,serial_port_baud_rate,serial_port_data_format,pages)";public boolean saveAttrExtItem(final List<AttrExtItem> listAttrExtItem,final int attrExtMainid) {boolean result = true;if (listAttrExtItem == null || listAttrExtItem.size() == 0)return false;StringBuffer buffer = new StringBuffer();try {buffer.append("begin;" );for (int i = 0; i < listAttrExtItem.size(); i++) {AttrExtItem att = listAttrExtItem.get(i);buffer.append(ADD_ATTR_EXT_ITEM);buffer.append(" values("+attrExtMainid+ ", " + att.getAttrNameKey()+ ", '" + att.getAttrType()+ "', '" + att.getDataType()+ "', '" + att.getMode()+ "', '" + att.getTolernace()+ "', '" + att.getTargetValue()+ "', '" + att.getAttrLowerValue()+ "', '" + att.getAttrHigherValue()+ "','" + att.getFetchAttrGroup()+ "', '" + att.getFetchAttrName()+ "', '" + att.getCalcExpression()+ "', '" + att.getSerialPort()+ "', " + att.getSerialPortbAUDRate()+ ", '" + att.getSerialPortDataFormat()+ "', '" + att.getPages()+"'"+ ");");}buffer.append("commit;");log.info("Add AttrExtItem sql: " + buffer.toString());this.getJdbcTemplate2().update(buffer.toString());} catch (Exception e) {result = false;log.error(e);}return result;}

转载于:https://www.cnblogs.com/jdw12306/p/9761338.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值