/** * 采用批方式插入多条数据 * * @param collection collection * @throws Exception */ public void insertAll(Collection collection) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("INSERT INTO LineLoss ("); buffer.append("LineCode,"); buffer.append("R,"); buffer.append("LineLong,"); buffer.append("Volt,"); buffer.append("T,"); buffer.append("ValidStatus,"); buffer.append("Flag,"); buffer.append("Remark "); buffer.append(") "); buffer.append("VALUES(?,?,?,?,?,?,?,?)"); if (logger.isDebugEnabled()) { logger.debug(buffer.toString()); } dbManager.prepareStatement(buffer.toString()); for (Iterator i = collection.iterator(); i.hasNext(); ) { LineLossDto lineLossDto = (LineLossDto) i.next(); dbManager.setString(1, lineLossDto.getLineCode()); dbManager.setDouble(2, lineLossDto.getR()); dbManager.setDouble(3, lineLossDto.getLineLong()); dbManager.setDouble(4, lineLossDto.getVolt()); dbManager.setDouble(5, lineLossDto.getT()); dbManager.setString(6, lineLossDto.getValidStatus()); dbManager.setString(7, lineLossDto.getFlag()); dbManager.setString(8, lineLossDto.getRemark()); dbManager.addBatch(); } dbManager.executePreparedUpdateBatch(); }
/** * 按主键更新一条数据(主键本身无法变更) * * @param lineLossDto lineLossDto * @throws Exception */ public void update(LineLossDto lineLossDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("UPDATE LineLoss SET "); buffer.append("R = ?, "); buffer.append("LineLong = ?, "); buffer.append("Volt = ?, "); buffer.append("T = ?, "); buffer.append("ValidStatus = ?, "); buffer.append("Flag = ?, "); buffer.append("Remark = ? "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append("UPDATE LineLoss SET "); debugBuffer.append("R = " + lineLossDto.getR() + ", "); debugBuffer.append("LineLong = " + lineLossDto.getLineLong() + ", "); debugBuffer.append("Volt = " + lineLossDto.getVolt() + ", "); debugBuffer.append("T = " + lineLossDto.getT() + ", "); debugBuffer.append("ValidStatus = '" + lineLossDto.getValidStatus() + "', "); debugBuffer.append("Flag = '" + lineLossDto.getFlag() + "', "); debugBuffer.append("Remark = '" + lineLossDto.getRemark() + "' "); debugBuffer.append("WHERE "); debugBuffer.append("LineCode=").append("'").append(lineLossDto.getLineCode()).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("LineCode = ?"); dbManager.prepareStatement(buffer.toString()); // 设置更新字段; dbManager.setDouble(1, lineLossDto.getR()); dbManager.setDouble(2, lineLossDto.getLineLong()); dbManager.setDouble(3, lineLossDto.getVolt()); dbManager.setDouble(4, lineLossDto.getT()); dbManager.setString(5, lineLossDto.getValidStatus()); dbManager.setString(6, lineLossDto.getFlag()); dbManager.setString(7, lineLossDto.getRemark()); // 设置条件字段; dbManager.setString(8, lineLossDto.getLineCode()); dbManager.executePreparedUpdate(); }
/** * 插入一条数据 * * @param lineLossDto lineLossDto * @throws Exception */ public void insert(LineLossDto lineLossDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("INSERT INTO LineLoss ("); buffer.append("LineCode,"); buffer.append("R,"); buffer.append("LineLong,"); buffer.append("Volt,"); buffer.append("T,"); buffer.append("ValidStatus,"); buffer.append("Flag,"); buffer.append("Remark "); buffer.append(") "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("VALUES("); debugBuffer.append("'").append(lineLossDto.getLineCode()).append("',"); debugBuffer.append("").append(lineLossDto.getR()).append(","); debugBuffer.append("").append(lineLossDto.getLineLong()).append(","); debugBuffer.append("").append(lineLossDto.getVolt()).append(","); debugBuffer.append("").append(lineLossDto.getT()).append(","); debugBuffer.append("'").append(lineLossDto.getValidStatus()).append("',"); debugBuffer.append("'").append(lineLossDto.getFlag()).append("',"); debugBuffer.append("'").append(lineLossDto.getRemark()).append("')"); logger.debug(debugBuffer.toString()); } buffer.append("VALUES(?,?,?,?,?,?,?,?)"); dbManager.prepareStatement(buffer.toString()); dbManager.setString(1, lineLossDto.getLineCode()); dbManager.setDouble(2, lineLossDto.getR()); dbManager.setDouble(3, lineLossDto.getLineLong()); dbManager.setDouble(4, lineLossDto.getVolt()); dbManager.setDouble(5, lineLossDto.getT()); dbManager.setString(6, lineLossDto.getValidStatus()); dbManager.setString(7, lineLossDto.getFlag()); dbManager.setString(8, lineLossDto.getRemark()); dbManager.executePreparedUpdate(); }