/** * 按主键更新一条数据(主键本身无法变更) * * @param lwWholeSalePriceDto lwWholeSalePriceDto * @throws Exception */ public void update(LwWholeSalePriceDto lwWholeSalePriceDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("UPDATE LwWholeSalePrice SET "); buffer.append("PowerClass = ?, "); buffer.append("VoltageEnd = ?, "); buffer.append("Price = ?, "); buffer.append("ValidStatus = ?, "); buffer.append("Flag = ?, "); buffer.append("Remark = ? "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append("UPDATE LwWholeSalePrice SET "); debugBuffer.append("PowerClass = '" + lwWholeSalePriceDto.getPowerClass() + "', "); debugBuffer.append("VoltageEnd = " + lwWholeSalePriceDto.getVoltageEnd() + ", "); debugBuffer.append("Price = " + lwWholeSalePriceDto.getPrice() + ", "); debugBuffer.append("ValidStatus = '" + lwWholeSalePriceDto.getValidStatus() + "', "); debugBuffer.append("Flag = '" + lwWholeSalePriceDto.getFlag() + "', "); debugBuffer.append("Remark = '" + lwWholeSalePriceDto.getRemark() + "' "); debugBuffer.append("WHERE "); debugBuffer .append("SaleArea=") .append("'") .append(lwWholeSalePriceDto.getSaleArea()) .append("' AND "); debugBuffer .append("VoltageBegin=") .append("") .append(lwWholeSalePriceDto.getVoltageBegin()) .append(""); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("SaleArea = ? And "); buffer.append("VoltageBegin = ?"); dbManager.prepareStatement(buffer.toString()); // 设置更新字段; dbManager.setString(1, lwWholeSalePriceDto.getPowerClass()); dbManager.setDouble(2, lwWholeSalePriceDto.getVoltageEnd()); dbManager.setDouble(3, lwWholeSalePriceDto.getPrice()); dbManager.setString(4, lwWholeSalePriceDto.getValidStatus()); dbManager.setString(5, lwWholeSalePriceDto.getFlag()); dbManager.setString(6, lwWholeSalePriceDto.getRemark()); // 设置条件字段; dbManager.setString(7, lwWholeSalePriceDto.getSaleArea()); dbManager.setDouble(8, lwWholeSalePriceDto.getVoltageBegin()); dbManager.executePreparedUpdate(); }
/** * 采用批方式插入多条数据 * * @param collection collection * @throws Exception */ public void insertAll(Collection collection) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("INSERT INTO LwWholeSalePrice ("); buffer.append("PowerClass,"); buffer.append("SaleArea,"); buffer.append("VoltageBegin,"); buffer.append("VoltageEnd,"); buffer.append("Price,"); 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(); ) { LwWholeSalePriceDto lwWholeSalePriceDto = (LwWholeSalePriceDto) i.next(); dbManager.setString(1, lwWholeSalePriceDto.getPowerClass()); dbManager.setString(2, lwWholeSalePriceDto.getSaleArea()); dbManager.setDouble(3, lwWholeSalePriceDto.getVoltageBegin()); dbManager.setDouble(4, lwWholeSalePriceDto.getVoltageEnd()); dbManager.setDouble(5, lwWholeSalePriceDto.getPrice()); dbManager.setString(6, lwWholeSalePriceDto.getValidStatus()); dbManager.setString(7, lwWholeSalePriceDto.getFlag()); dbManager.setString(8, lwWholeSalePriceDto.getRemark()); dbManager.addBatch(); } dbManager.executePreparedUpdateBatch(); }
/** * 插入一条数据 * * @param lwWholeSalePriceDto lwWholeSalePriceDto * @throws Exception */ public void insert(LwWholeSalePriceDto lwWholeSalePriceDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("INSERT INTO LwWholeSalePrice ("); buffer.append("PowerClass,"); buffer.append("SaleArea,"); buffer.append("VoltageBegin,"); buffer.append("VoltageEnd,"); buffer.append("Price,"); 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(lwWholeSalePriceDto.getPowerClass()).append("',"); debugBuffer.append("'").append(lwWholeSalePriceDto.getSaleArea()).append("',"); debugBuffer.append("").append(lwWholeSalePriceDto.getVoltageBegin()).append(","); debugBuffer.append("").append(lwWholeSalePriceDto.getVoltageEnd()).append(","); debugBuffer.append("").append(lwWholeSalePriceDto.getPrice()).append(","); debugBuffer.append("'").append(lwWholeSalePriceDto.getValidStatus()).append("',"); debugBuffer.append("'").append(lwWholeSalePriceDto.getFlag()).append("',"); debugBuffer.append("'").append(lwWholeSalePriceDto.getRemark()).append("')"); logger.debug(debugBuffer.toString()); } buffer.append("VALUES(?,?,?,?,?,?,?,?)"); dbManager.prepareStatement(buffer.toString()); dbManager.setString(1, lwWholeSalePriceDto.getPowerClass()); dbManager.setString(2, lwWholeSalePriceDto.getSaleArea()); dbManager.setDouble(3, lwWholeSalePriceDto.getVoltageBegin()); dbManager.setDouble(4, lwWholeSalePriceDto.getVoltageEnd()); dbManager.setDouble(5, lwWholeSalePriceDto.getPrice()); dbManager.setString(6, lwWholeSalePriceDto.getValidStatus()); dbManager.setString(7, lwWholeSalePriceDto.getFlag()); dbManager.setString(8, lwWholeSalePriceDto.getRemark()); dbManager.executePreparedUpdate(); }