public void update(GenericVO vo) throws AppException, SysException { ProvinceSVO province = (ProvinceSVO) vo; StringBuffer sql = new StringBuffer("update PROVINCE set"); if (province.getName() != null) { sql.append(" NAME=?,"); } sql = sql.delete(sql.length() - 1, sql.length()); sql.append(" where 1=1"); sql.append(" and PROV_ID=?"); Connection connection = null; PreparedStatement ps = null; try { connection = ConnectionFactory.getConnection(); ps = connection.prepareStatement(sql.toString()); int index = 1; if (province.getName() != null) { ps.setString(index++, province.getName()); } ps.setString(index++, province.getProvId()); ps.execute(); } catch (SQLException e) { throw new SysException("", "update error..", e); } finally { try { if (ps != null) { ps.close(); } } catch (SQLException e) { } } }
/** * Get individual Change HTML * * @param sb string to append to * @param columnName column name */ private void getChangeHTML(StringBuffer sb, String columnName) { if (get_Value(columnName) != null) { if (sb.length() > 0) sb.append("<br>"); sb.append(Msg.getElement(getCtx(), columnName)) .append(": ") .append(get_DisplayValue(columnName, true)); } else { String nc = getNullColumns(); if (nc != null && nc.indexOf(columnName) != -1) { if (sb.length() > 0) sb.append("<br>"); sb.append("(").append(Msg.getElement(getCtx(), columnName)).append(")"); } } } // getChangeHTML
// return all grantees: thr_0, thr_1, thr_2 ..., excluding itself private static String getAllGrantees() { StringBuffer aStr = new StringBuffer(" "); Map<String, String> userPasswd = (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap); for (Map.Entry<String, String> e : userPasswd.entrySet()) { if (!e.getKey().equalsIgnoreCase("thr_" + RemoteTestModule.getCurrentThread().getThreadId())) aStr.append(e.getKey() + ", "); } if (aStr.charAt(aStr.length() - 2) == ',') { aStr.deleteCharAt(aStr.length() - 2); } aStr.deleteCharAt(0); // delete the leading space return aStr.toString(); }
// return optionally any insert, delete, trigger, select [col list], update [col list] private String getPrivilegeLists(String tableName) { StringBuffer aStr = new StringBuffer(" "); for (int i = 0; i < tablePriv.length; i++) { if (SQLTest.random.nextBoolean()) { aStr.append(tablePriv[i]); // insert delete etc if (i > 2) { aStr.append(getColumnLists(tableName)); // column list for the table } // may include column list aStr.append(", "); } } if (aStr.charAt(aStr.length() - 2) == ',') { aStr.deleteCharAt(aStr.length() - 2); } aStr.deleteCharAt(0); // delete the leading space return aStr.toString(); }
// returns column list: column-id, column-id ... private String getColumnLists(String tableName) { List<String> colNames = (List<String>) tableCols.get(tableName); StringBuffer aStr = new StringBuffer(" "); for (int i = 0; i < colNames.size(); i++) { if (SQLTest.random.nextBoolean()) { aStr.append(colNames.get(i) + ", "); } } if (aStr.charAt(aStr.length() - 2) == ',') { aStr.deleteCharAt(aStr.length() - 2); } aStr.deleteCharAt(0); // delete the leading space if (aStr.length() != 1) { aStr.insert(1, '('); aStr.append(')'); } // has column return aStr.toString(); }
public static String escapeBadSqlPatternChars(String s) { StringBuffer sb = new StringBuffer(s); for (int i = 0, len = sb.length(); i < len; ++i) if (sb.charAt(i) == '\'') { sb.insert(i, '\''); ++len; i += 2; } return sb.toString(); }
/** * Update the SQL string and replace the ? markers with parameter names eg @P0, @P1 etc. * * @param sql the SQL containing markers to substitute * @param list the parameter list * @return the modified SQL as a <code>String</code> */ static String substituteParamMarkers(String sql, ParamInfo[] list) { // A parameter can have at most 8 characters: " @P" plus at most 4 // digits plus " ". We subtract the "?" placeholder, that's at most // 7 extra characters needed for each parameter. char[] buf = new char[sql.length() + list.length * 7]; int bufferPtr = 0; // Output buffer pointer int start = 0; // Input string pointer StringBuffer number = new StringBuffer(4); for (int i = 0; i < list.length; i++) { int pos = list[i].markerPos; if (pos > 0) { sql.getChars(start, pos, buf, bufferPtr); bufferPtr += (pos - start); start = pos + 1; // Append " @P" buf[bufferPtr++] = ' '; buf[bufferPtr++] = '@'; buf[bufferPtr++] = 'P'; // Append parameter number // Rather complicated, but it's the only way in which no // unnecessary objects are created number.setLength(0); number.append(i); number.getChars(0, number.length(), buf, bufferPtr); bufferPtr += number.length(); // Append " " buf[bufferPtr++] = ' '; } } if (start < sql.length()) { sql.getChars(start, sql.length(), buf, bufferPtr); bufferPtr += (sql.length() - start); } return new String(buf, 0, bufferPtr); }
// any number of users excluding itself private static String getGrantees(int num) { StringBuffer aStr = new StringBuffer(" "); Map<String, String> userPasswd = (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap); userPasswd.remove("thr_" + RemoteTestModule.getCurrentThread().getThreadId()); String[] users = new String[userPasswd.size()]; userPasswd.keySet().toArray(users); int i = 0; while (i < num) { int x = SQLTest.random.nextInt(users.length); aStr.append(users[x] + ", "); i++; } if (aStr.charAt(aStr.length() - 2) == ',') { aStr.deleteCharAt(aStr.length() - 2); } aStr.deleteCharAt(0); // delete the leading space return aStr.toString(); }
/** * 按主键更新一条数据(主键本身无法变更) * * @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(); }
private void addModuleScore(Connection conn, List row, int modId, int studId, boolean isPractice) throws SQLException { ResultSet rs = null; PreparedStatement stmt = null; try { String q = "select isCorrect,userInput,eventType,qid from eventlog where userid=? and (eventType='survey.evalq' or eventType='evalq' or eventType='evaltq' or eventType='survey.evaltq') and modId=?"; stmt = conn.prepareStatement(q); stmt.setInt(1, studId); stmt.setInt(2, modId); rs = stmt.executeQuery(); StringBuffer surveyAnswers = new StringBuffer(); int nQuestions = 0; int nCorrect = 0; while (rs.next()) { boolean isCorrect = rs.getBoolean(1); String input = rs.getString(2); String eventType = rs.getString(3); int qid = rs.getInt(4); if (eventType.equals("survey.evalq") || eventType.equals("survey.evaltq")) surveyAnswers.append("(" + qid + " " + input + ") |"); else { nQuestions++; if (isCorrect) nCorrect++; } } if (surveyAnswers.length() > 0) surveyAnswers.deleteCharAt(surveyAnswers.length() - 1); if (!isPractice) row.add(String.format("%5.2f", (nCorrect / ((double) nQuestions) * 100.0))); else row.add(""); row.add(surveyAnswers.toString()); } finally { if (stmt != null) stmt.close(); if (rs != null) rs.close(); } }
/** * 按主键查找一条数据 * * @param saleArea 趸售区域 * @param voltageBegin 起始电压 * @return LwWholeSalePriceDto * @throws Exception */ public LwWholeSalePriceDto findByPrimaryKey(String saleArea, double voltageBegin) throws Exception { StringBuffer buffer = new StringBuffer(200); // 拼SQL语句 buffer.append("SELECT "); 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("FROM LwWholeSalePrice "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("SaleArea=").append("'").append(saleArea).append("' AND "); debugBuffer.append("VoltageBegin=").append("").append(voltageBegin).append(""); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("SaleArea = ? And "); buffer.append("VoltageBegin = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, saleArea); dbManager.setDouble(2, voltageBegin); ResultSet resultSet = dbManager.executePreparedQuery(); LwWholeSalePriceDto lwWholeSalePriceDto = null; if (resultSet.next()) { lwWholeSalePriceDto = new LwWholeSalePriceDto(); lwWholeSalePriceDto.setPowerClass(dbManager.getString(resultSet, 1)); lwWholeSalePriceDto.setSaleArea(dbManager.getString(resultSet, 2)); lwWholeSalePriceDto.setVoltageBegin(dbManager.getDouble(resultSet, 3)); lwWholeSalePriceDto.setVoltageEnd(dbManager.getDouble(resultSet, 4)); lwWholeSalePriceDto.setPrice(dbManager.getDouble(resultSet, 5)); lwWholeSalePriceDto.setValidStatus(dbManager.getString(resultSet, 6)); lwWholeSalePriceDto.setFlag(dbManager.getString(resultSet, 7)); lwWholeSalePriceDto.setRemark(dbManager.getString(resultSet, 8)); } resultSet.close(); return lwWholeSalePriceDto; }
/** * 按主键查找一条数据 * * @param lineCode 线路名称 * @return LineLossDto * @throws Exception */ public LineLossDto findByPrimaryKey(String lineCode) throws Exception { StringBuffer buffer = new StringBuffer(200); // 拼SQL语句 buffer.append("SELECT "); 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("FROM LineLoss "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("LineCode=").append("'").append(lineCode).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("LineCode = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, lineCode); ResultSet resultSet = dbManager.executePreparedQuery(); LineLossDto lineLossDto = null; if (resultSet.next()) { lineLossDto = new LineLossDto(); lineLossDto.setLineCode(dbManager.getString(resultSet, 1)); lineLossDto.setR(dbManager.getDouble(resultSet, 2)); lineLossDto.setLineLong(dbManager.getDouble(resultSet, 3)); lineLossDto.setVolt(dbManager.getDouble(resultSet, 4)); lineLossDto.setT(dbManager.getDouble(resultSet, 5)); lineLossDto.setValidStatus(dbManager.getString(resultSet, 6)); lineLossDto.setFlag(dbManager.getString(resultSet, 7)); lineLossDto.setRemark(dbManager.getString(resultSet, 8)); } resultSet.close(); return lineLossDto; }
/** * 按主键删除一条数据 * * @param lineCode 线路名称 * @throws Exception */ public void delete(String lineCode) throws Exception { StringBuffer buffer = new StringBuffer(100); buffer.append("DELETE FROM LineLoss "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("LineCode=").append("'").append(lineCode).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("LineCode = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, lineCode); dbManager.executePreparedUpdate(); }
/** * 按主键更新一条数据(主键本身无法变更) * * @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(); }
/** * 按主键删除一条数据 * * @param saleArea 趸售区域 * @param voltageBegin 起始电压 * @throws Exception */ public void delete(String saleArea, double voltageBegin) throws Exception { StringBuffer buffer = new StringBuffer(100); buffer.append("DELETE FROM LwWholeSalePrice "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("SaleArea=").append("'").append(saleArea).append("' AND "); debugBuffer.append("VoltageBegin=").append("").append(voltageBegin).append(""); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("SaleArea = ? And "); buffer.append("VoltageBegin = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, saleArea); dbManager.setDouble(2, voltageBegin); dbManager.executePreparedUpdate(); }
/** * Get Changes as HTML string * * @return changes */ public String getChangesHTML() { StringBuffer sb = new StringBuffer(); getChangeHTML(sb, "Priority"); getChangeHTML(sb, "PriorityUser"); getChangeHTML(sb, "R_Category_ID"); getChangeHTML(sb, "R_Group_ID"); getChangeHTML(sb, "R_RequestType_ID"); getChangeHTML(sb, "R_Resolution_ID"); getChangeHTML(sb, "R_Status_ID"); getChangeHTML(sb, "SalesRep_ID"); getChangeHTML(sb, "Summary"); // // getChangeHTML(sb, "AD_Org_ID"); // always stored getChangeHTML(sb, "AD_Role_ID"); getChangeHTML(sb, "AD_User_ID"); getChangeHTML(sb, "C_Activity_ID"); getChangeHTML(sb, "C_BPartner_ID"); getChangeHTML(sb, "C_Invoice_ID"); getChangeHTML(sb, "C_Order_ID"); getChangeHTML(sb, "C_Payment_ID"); getChangeHTML(sb, "C_Project_ID"); getChangeHTML(sb, "DateNextAction"); getChangeHTML(sb, "IsEscalated"); getChangeHTML(sb, "IsInvoiced"); getChangeHTML(sb, "IsSelfService"); getChangeHTML(sb, "M_InOut_ID"); getChangeHTML(sb, "M_Product_ID"); getChangeHTML(sb, "A_Asset_ID"); if (sb.length() == 0) sb.append("./."); // Unicode check char[] chars = sb.toString().toCharArray(); sb = new StringBuffer(chars.length); for (char c : chars) { if (c > 255) sb.append("&#").append(c).append(";"); else sb.append(c); } return sb.toString(); } // getChangesHTML
/** * 按主键删除一条数据 * * @param lineCode 线路代码 * @param statMonth 统计年月 * @throws Exception */ public void delete(String lineCode, String statMonth) throws Exception { StringBuffer buffer = new StringBuffer(100); buffer.append("DELETE FROM LwWholeSaleSummary "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("LineCode=").append("'").append(lineCode).append("' AND "); debugBuffer.append("StatMonth=").append("'").append(statMonth).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("LineCode = ? And "); buffer.append("StatMonth = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, lineCode); dbManager.setString(2, statMonth); dbManager.executePreparedUpdate(); }
/** * 插入一条数据 * * @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(); }
/** * 按主键删除一条数据 * * @param userNo 户号 * @param statMonth 账期 * @throws Exception */ public void delete(String userNo, String statMonth) throws Exception { StringBuffer buffer = new StringBuffer(100); buffer.append("DELETE FROM LwTownIndicator "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("UserNo=").append("'").append(userNo).append("' AND "); debugBuffer.append("StatMonth=").append("'").append(statMonth).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("UserNo = ? And "); buffer.append("StatMonth = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, userNo); dbManager.setString(2, statMonth); dbManager.executePreparedUpdate(); }
public void update(GenericVO vo) throws AppException, SysException { StaffWorkAreaSVO staffWorkArea = (StaffWorkAreaSVO) vo; StringBuffer sql = new StringBuffer("update STAFF_WORK_AREA set"); if (staffWorkArea.getStaffId() != null) { sql.append(" STAFF_ID=?,"); } if (staffWorkArea.getWorkAreaId() != null) { sql.append(" WORK_AREA_ID=?,"); } if (staffWorkArea.getGrantor() != null) { sql.append(" GRANTOR=?,"); } if (staffWorkArea.getAdminFlag() != null) { sql.append(" ADMIN_FLAG=?,"); } if (staffWorkArea.getSts() != null) { sql.append(" STS=?,"); } if (staffWorkArea.getStsDate() != null) { sql.append(" STS_DATE=?,"); } if (staffWorkArea.getCreateDate() != null) { sql.append(" CREATE_DATE=?,"); } sql = sql.delete(sql.length() - 1, sql.length()); sql.append(" where 1=1"); sql.append(" and STAFF_WORK_AREA_ID=?"); Connection connection = null; PreparedStatement ps = null; try { connection = ConnectionFactory.getConnection(); ps = connection.prepareStatement(sql.toString()); int index = 1; if (staffWorkArea.getStaffId() != null) { ps.setString(index++, staffWorkArea.getStaffId()); } if (staffWorkArea.getWorkAreaId() != null) { ps.setString(index++, staffWorkArea.getWorkAreaId()); } if (staffWorkArea.getGrantor() != null) { ps.setString(index++, staffWorkArea.getGrantor()); } if (staffWorkArea.getAdminFlag() != null) { ps.setString(index++, staffWorkArea.getAdminFlag()); } if (staffWorkArea.getSts() != null) { ps.setString(index++, staffWorkArea.getSts()); } if (staffWorkArea.getStsDate() != null) { ps.setDate(index++, staffWorkArea.getStsDate()); } if (staffWorkArea.getCreateDate() != null) { ps.setDate(index++, staffWorkArea.getCreateDate()); } ps.setString(index++, staffWorkArea.getStaffWorkAreaId()); ps.execute(); } catch (SQLException e) { throw new SysException("", "update error..", e); } finally { try { if (ps != null) { ps.close(); } } catch (SQLException e) { } } }
// 88.5 public SmTbProductBean[] loadUsingTemplate(SmTbProductBean pObject, int startRow, int numRows) throws SQLException { Connection c = null; PreparedStatement ps = null; StringBuffer where = new StringBuffer(""); StringBuffer _sql = new StringBuffer("SELECT " + ALL_FIELDS + " from sm_tb_product WHERE "); StringBuffer _sqlWhere = new StringBuffer(""); try { int _dirtyCount = 0; if (pObject.isPrdIdModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("prd_id= ?"); } if (pObject.isPrdTypeIdModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("prd_type_id= ?"); } if (pObject.isNameModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("name= ?"); } if (pObject.isPriceModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("price= ?"); } if (pObject.isPriceVipModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("price_vip= ?"); } if (pObject.isSuplyStatusModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("suply_status= ?"); } if (pObject.isFormatDescModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("format_desc= ?"); } if (pObject.isDetailDescModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("detail_desc= ?"); } if (pObject.isSendAreaModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("send_area= ?"); } if (pObject.isSendDescModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("send_desc= ?"); } if (pObject.isPrdPicFileModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("prd_pic_file= ?"); } if (pObject.isOwnerModified()) { _dirtyCount++; _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("owner= ?"); } if (_dirtyCount == 0) { throw new SQLException("The pObject to look for is invalid : not initialized !"); } _sql.append(_sqlWhere); c = getConnection(); ps = c.prepareStatement( _sql.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); _dirtyCount = 0; if (pObject.isPrdIdModified()) { Manager.setLong(ps, ++_dirtyCount, pObject.getPrdId()); } if (pObject.isPrdTypeIdModified()) { Manager.setLong(ps, ++_dirtyCount, pObject.getPrdTypeId()); } if (pObject.isNameModified()) { ps.setString(++_dirtyCount, pObject.getName()); } if (pObject.isPriceModified()) { Manager.setLong(ps, ++_dirtyCount, pObject.getPrice()); } if (pObject.isPriceVipModified()) { Manager.setLong(ps, ++_dirtyCount, pObject.getPriceVip()); } if (pObject.isSuplyStatusModified()) { ps.setString(++_dirtyCount, pObject.getSuplyStatus()); } if (pObject.isFormatDescModified()) { ps.setString(++_dirtyCount, pObject.getFormatDesc()); } if (pObject.isDetailDescModified()) { ps.setString(++_dirtyCount, pObject.getDetailDesc()); } if (pObject.isSendAreaModified()) { ps.setString(++_dirtyCount, pObject.getSendArea()); } if (pObject.isSendDescModified()) { ps.setString(++_dirtyCount, pObject.getSendDesc()); } if (pObject.isPrdPicFileModified()) { ps.setString(++_dirtyCount, pObject.getPrdPicFile()); } if (pObject.isOwnerModified()) { Manager.setLong(ps, ++_dirtyCount, pObject.getOwner()); } ps.executeQuery(); return loadByPreparedStatement(ps, null, startRow, numRows); } finally { getManager().close(ps); freeConnection(c); } }
/** * 按主键查找一条数据 * * @param lineCode 线路代码 * @param statMonth 统计年月 * @return LwWholeSaleSummaryDto * @throws Exception */ public LwWholeSaleSummaryDto findByPrimaryKey(String lineCode, String statMonth) throws Exception { StringBuffer buffer = new StringBuffer(200); // 拼SQL语句 buffer.append("SELECT "); buffer.append("LineCode,"); buffer.append("StatMonth,"); buffer.append("PowerClass,"); buffer.append("ElectricQuantity,"); buffer.append("PointerQuantity,"); buffer.append("SanXiaFee,"); buffer.append("Surcharge,"); buffer.append("SumFee,"); buffer.append("ValidStatus,"); buffer.append("Flag,"); buffer.append("Remark,"); buffer.append("TransLoss,"); buffer.append("LineLoss,"); buffer.append("UnPointerQuantity,"); buffer.append("RateCode,"); buffer.append("AdjustRate,"); buffer.append("FarmUseScale,"); buffer.append("FarmUsePrice,"); buffer.append("FarmUseQuantity,"); buffer.append("FarmUseFee,"); buffer.append("ProductScale,"); buffer.append("ProductPrice,"); buffer.append("ProductQuantity,"); buffer.append("ProductFee,"); buffer.append("DenizenScale,"); buffer.append("DenizenPrice,"); buffer.append("DenizenQuantity,"); buffer.append("DenizenFee,"); buffer.append("UnDenizenScale,"); buffer.append("UnDenizenPrice,"); buffer.append("UnDenizenQuantity,"); buffer.append("UnDenizenFee,"); buffer.append("IndustryScale,"); buffer.append("IndustryPrice,"); buffer.append("IndustryQuantity,"); buffer.append("IndustryFee,"); buffer.append("BizScale,"); buffer.append("BizPrice,"); buffer.append("BizQuantity,"); buffer.append("BizFee,"); buffer.append("PowerRateFee,"); buffer.append("UpCompany,"); buffer.append("PowerFee,"); buffer.append("InputDate,"); buffer.append("Kv,"); buffer.append("Wholesaletype,"); buffer.append("WorkNum,"); buffer.append("UnWorkNum,"); buffer.append("OtherSurcharge,"); buffer.append("DifferenceQuantity,"); buffer.append("UnTransLoss,"); buffer.append("UnLineLoss "); buffer.append("FROM LwWholeSaleSummary "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("LineCode=").append("'").append(lineCode).append("' AND "); debugBuffer.append("StatMonth=").append("'").append(statMonth).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("LineCode = ? And "); buffer.append("StatMonth = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, lineCode); dbManager.setString(2, statMonth); ResultSet resultSet = dbManager.executePreparedQuery(); LwWholeSaleSummaryDto lwWholeSaleSummaryDto = null; if (resultSet.next()) { lwWholeSaleSummaryDto = new LwWholeSaleSummaryDto(); lwWholeSaleSummaryDto.setLineCode(dbManager.getString(resultSet, 1)); lwWholeSaleSummaryDto.setStatMonth(dbManager.getString(resultSet, 2)); lwWholeSaleSummaryDto.setPowerClass(dbManager.getString(resultSet, 3)); lwWholeSaleSummaryDto.setElectricQuantity(dbManager.getDouble(resultSet, 4)); lwWholeSaleSummaryDto.setPointerQuantity(dbManager.getDouble(resultSet, 5)); lwWholeSaleSummaryDto.setSanXiaFee(dbManager.getDouble(resultSet, 6)); lwWholeSaleSummaryDto.setSurcharge(dbManager.getDouble(resultSet, 7)); lwWholeSaleSummaryDto.setSumFee(dbManager.getDouble(resultSet, 8)); lwWholeSaleSummaryDto.setValidStatus(dbManager.getString(resultSet, 9)); lwWholeSaleSummaryDto.setFlag(dbManager.getString(resultSet, 10)); lwWholeSaleSummaryDto.setRemark(dbManager.getString(resultSet, 11)); lwWholeSaleSummaryDto.setTransLoss(dbManager.getDouble(resultSet, 12)); lwWholeSaleSummaryDto.setLineLoss(dbManager.getDouble(resultSet, 13)); lwWholeSaleSummaryDto.setUnPointerQuantity(dbManager.getDouble(resultSet, 14)); lwWholeSaleSummaryDto.setRateCode(dbManager.getDouble(resultSet, 15)); lwWholeSaleSummaryDto.setAdjustRate(dbManager.getDouble(resultSet, 16)); lwWholeSaleSummaryDto.setFarmUseScale(dbManager.getDouble(resultSet, 17)); lwWholeSaleSummaryDto.setFarmUsePrice(dbManager.getDouble(resultSet, 18)); lwWholeSaleSummaryDto.setFarmUseQuantity(dbManager.getDouble(resultSet, 19)); lwWholeSaleSummaryDto.setFarmUseFee(dbManager.getDouble(resultSet, 20)); lwWholeSaleSummaryDto.setProductScale(dbManager.getDouble(resultSet, 21)); lwWholeSaleSummaryDto.setProductPrice(dbManager.getDouble(resultSet, 22)); lwWholeSaleSummaryDto.setProductQuantity(dbManager.getDouble(resultSet, 23)); lwWholeSaleSummaryDto.setProductFee(dbManager.getDouble(resultSet, 24)); lwWholeSaleSummaryDto.setDenizenScale(dbManager.getDouble(resultSet, 25)); lwWholeSaleSummaryDto.setDenizenPrice(dbManager.getDouble(resultSet, 26)); lwWholeSaleSummaryDto.setDenizenQuantity(dbManager.getDouble(resultSet, 27)); lwWholeSaleSummaryDto.setDenizenFee(dbManager.getDouble(resultSet, 28)); lwWholeSaleSummaryDto.setUnDenizenScale(dbManager.getDouble(resultSet, 29)); lwWholeSaleSummaryDto.setUnDenizenPrice(dbManager.getDouble(resultSet, 30)); lwWholeSaleSummaryDto.setUnDenizenQuantity(dbManager.getDouble(resultSet, 31)); lwWholeSaleSummaryDto.setUnDenizenFee(dbManager.getDouble(resultSet, 32)); lwWholeSaleSummaryDto.setIndustryScale(dbManager.getDouble(resultSet, 33)); lwWholeSaleSummaryDto.setIndustryPrice(dbManager.getDouble(resultSet, 34)); lwWholeSaleSummaryDto.setIndustryQuantity(dbManager.getDouble(resultSet, 35)); lwWholeSaleSummaryDto.setIndustryFee(dbManager.getDouble(resultSet, 36)); lwWholeSaleSummaryDto.setBizScale(dbManager.getDouble(resultSet, 37)); lwWholeSaleSummaryDto.setBizPrice(dbManager.getDouble(resultSet, 38)); lwWholeSaleSummaryDto.setBizQuantity(dbManager.getDouble(resultSet, 39)); lwWholeSaleSummaryDto.setBizFee(dbManager.getDouble(resultSet, 40)); lwWholeSaleSummaryDto.setPowerRateFee(dbManager.getDouble(resultSet, 41)); lwWholeSaleSummaryDto.setUpCompany(dbManager.getString(resultSet, 42)); lwWholeSaleSummaryDto.setPowerFee(dbManager.getDouble(resultSet, 43)); lwWholeSaleSummaryDto.setInputDate(dbManager.getString(resultSet, 44)); lwWholeSaleSummaryDto.setKv(dbManager.getString(resultSet, 45)); lwWholeSaleSummaryDto.setWholesaletype(dbManager.getString(resultSet, 46)); lwWholeSaleSummaryDto.setWorkNum(dbManager.getDouble(resultSet, 47)); lwWholeSaleSummaryDto.setUnWorkNum(dbManager.getDouble(resultSet, 48)); lwWholeSaleSummaryDto.setOtherSurcharge(dbManager.getDouble(resultSet, 49)); lwWholeSaleSummaryDto.setDifferenceQuantity(dbManager.getString(resultSet, 50)); lwWholeSaleSummaryDto.setUnTransLoss(dbManager.getDouble(resultSet, 51)); lwWholeSaleSummaryDto.setUnLineLoss(dbManager.getDouble(resultSet, 52)); } resultSet.close(); return lwWholeSaleSummaryDto; }
/** * 按主键更新一条数据(主键本身无法变更) * * @param lwWholeSaleSummaryDto lwWholeSaleSummaryDto * @throws Exception */ public void update(LwWholeSaleSummaryDto lwWholeSaleSummaryDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("UPDATE LwWholeSaleSummary SET "); buffer.append("PowerClass = ?, "); buffer.append("ElectricQuantity = ?, "); buffer.append("PointerQuantity = ?, "); buffer.append("SanXiaFee = ?, "); buffer.append("Surcharge = ?, "); buffer.append("SumFee = ?, "); buffer.append("ValidStatus = ?, "); buffer.append("Flag = ?, "); buffer.append("Remark = ?, "); buffer.append("TransLoss = ?, "); buffer.append("LineLoss = ?, "); buffer.append("UnPointerQuantity = ?, "); buffer.append("RateCode = ?, "); buffer.append("AdjustRate = ?, "); buffer.append("FarmUseScale = ?, "); buffer.append("FarmUsePrice = ?, "); buffer.append("FarmUseQuantity = ?, "); buffer.append("FarmUseFee = ?, "); buffer.append("ProductScale = ?, "); buffer.append("ProductPrice = ?, "); buffer.append("ProductQuantity = ?, "); buffer.append("ProductFee = ?, "); buffer.append("DenizenScale = ?, "); buffer.append("DenizenPrice = ?, "); buffer.append("DenizenQuantity = ?, "); buffer.append("DenizenFee = ?, "); buffer.append("UnDenizenScale = ?, "); buffer.append("UnDenizenPrice = ?, "); buffer.append("UnDenizenQuantity = ?, "); buffer.append("UnDenizenFee = ?, "); buffer.append("IndustryScale = ?, "); buffer.append("IndustryPrice = ?, "); buffer.append("IndustryQuantity = ?, "); buffer.append("IndustryFee = ?, "); buffer.append("BizScale = ?, "); buffer.append("BizPrice = ?, "); buffer.append("BizQuantity = ?, "); buffer.append("BizFee = ?, "); buffer.append("PowerRateFee = ?, "); buffer.append("UpCompany = ?, "); buffer.append("PowerFee = ?, "); buffer.append("InputDate = ?, "); buffer.append("Kv = ?, "); buffer.append("Wholesaletype = ?, "); buffer.append("WorkNum = ?, "); buffer.append("UnWorkNum = ?, "); buffer.append("OtherSurcharge = ?, "); buffer.append("DifferenceQuantity = ?, "); buffer.append("UnTransLoss = ?, "); buffer.append("UnLineLoss = ? "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append("UPDATE LwWholeSaleSummary SET "); debugBuffer.append("PowerClass = '" + lwWholeSaleSummaryDto.getPowerClass() + "', "); debugBuffer.append( "ElectricQuantity = " + lwWholeSaleSummaryDto.getElectricQuantity() + ", "); debugBuffer.append("PointerQuantity = " + lwWholeSaleSummaryDto.getPointerQuantity() + ", "); debugBuffer.append("SanXiaFee = " + lwWholeSaleSummaryDto.getSanXiaFee() + ", "); debugBuffer.append("Surcharge = " + lwWholeSaleSummaryDto.getSurcharge() + ", "); debugBuffer.append("SumFee = " + lwWholeSaleSummaryDto.getSumFee() + ", "); debugBuffer.append("ValidStatus = '" + lwWholeSaleSummaryDto.getValidStatus() + "', "); debugBuffer.append("Flag = '" + lwWholeSaleSummaryDto.getFlag() + "', "); debugBuffer.append("Remark = '" + lwWholeSaleSummaryDto.getRemark() + "', "); debugBuffer.append("TransLoss = " + lwWholeSaleSummaryDto.getTransLoss() + ", "); debugBuffer.append("LineLoss = " + lwWholeSaleSummaryDto.getLineLoss() + ", "); debugBuffer.append( "UnPointerQuantity = " + lwWholeSaleSummaryDto.getUnPointerQuantity() + ", "); debugBuffer.append("RateCode = " + lwWholeSaleSummaryDto.getRateCode() + ", "); debugBuffer.append("AdjustRate = " + lwWholeSaleSummaryDto.getAdjustRate() + ", "); debugBuffer.append("FarmUseScale = " + lwWholeSaleSummaryDto.getFarmUseScale() + ", "); debugBuffer.append("FarmUsePrice = " + lwWholeSaleSummaryDto.getFarmUsePrice() + ", "); debugBuffer.append("FarmUseQuantity = " + lwWholeSaleSummaryDto.getFarmUseQuantity() + ", "); debugBuffer.append("FarmUseFee = " + lwWholeSaleSummaryDto.getFarmUseFee() + ", "); debugBuffer.append("ProductScale = " + lwWholeSaleSummaryDto.getProductScale() + ", "); debugBuffer.append("ProductPrice = " + lwWholeSaleSummaryDto.getProductPrice() + ", "); debugBuffer.append("ProductQuantity = " + lwWholeSaleSummaryDto.getProductQuantity() + ", "); debugBuffer.append("ProductFee = " + lwWholeSaleSummaryDto.getProductFee() + ", "); debugBuffer.append("DenizenScale = " + lwWholeSaleSummaryDto.getDenizenScale() + ", "); debugBuffer.append("DenizenPrice = " + lwWholeSaleSummaryDto.getDenizenPrice() + ", "); debugBuffer.append("DenizenQuantity = " + lwWholeSaleSummaryDto.getDenizenQuantity() + ", "); debugBuffer.append("DenizenFee = " + lwWholeSaleSummaryDto.getDenizenFee() + ", "); debugBuffer.append("UnDenizenScale = " + lwWholeSaleSummaryDto.getUnDenizenScale() + ", "); debugBuffer.append("UnDenizenPrice = " + lwWholeSaleSummaryDto.getUnDenizenPrice() + ", "); debugBuffer.append( "UnDenizenQuantity = " + lwWholeSaleSummaryDto.getUnDenizenQuantity() + ", "); debugBuffer.append("UnDenizenFee = " + lwWholeSaleSummaryDto.getUnDenizenFee() + ", "); debugBuffer.append("IndustryScale = " + lwWholeSaleSummaryDto.getIndustryScale() + ", "); debugBuffer.append("IndustryPrice = " + lwWholeSaleSummaryDto.getIndustryPrice() + ", "); debugBuffer.append( "IndustryQuantity = " + lwWholeSaleSummaryDto.getIndustryQuantity() + ", "); debugBuffer.append("IndustryFee = " + lwWholeSaleSummaryDto.getIndustryFee() + ", "); debugBuffer.append("BizScale = " + lwWholeSaleSummaryDto.getBizScale() + ", "); debugBuffer.append("BizPrice = " + lwWholeSaleSummaryDto.getBizPrice() + ", "); debugBuffer.append("BizQuantity = " + lwWholeSaleSummaryDto.getBizQuantity() + ", "); debugBuffer.append("BizFee = " + lwWholeSaleSummaryDto.getBizFee() + ", "); debugBuffer.append("PowerRateFee = " + lwWholeSaleSummaryDto.getPowerRateFee() + ", "); debugBuffer.append("UpCompany = '" + lwWholeSaleSummaryDto.getUpCompany() + "', "); debugBuffer.append("PowerFee = " + lwWholeSaleSummaryDto.getPowerFee() + ", "); debugBuffer.append("InputDate = '" + lwWholeSaleSummaryDto.getInputDate() + "', "); debugBuffer.append("Kv = '" + lwWholeSaleSummaryDto.getKv() + "', "); debugBuffer.append("Wholesaletype = '" + lwWholeSaleSummaryDto.getWholesaletype() + "', "); debugBuffer.append("WorkNum = " + lwWholeSaleSummaryDto.getWorkNum() + ", "); debugBuffer.append("UnWorkNum = " + lwWholeSaleSummaryDto.getUnWorkNum() + ", "); debugBuffer.append("OtherSurcharge = " + lwWholeSaleSummaryDto.getOtherSurcharge() + ", "); debugBuffer.append( "DifferenceQuantity = '" + lwWholeSaleSummaryDto.getDifferenceQuantity() + "', "); debugBuffer.append("UnTransLoss = " + lwWholeSaleSummaryDto.getUnTransLoss() + ", "); debugBuffer.append("UnLineLoss = " + lwWholeSaleSummaryDto.getUnLineLoss() + " "); debugBuffer.append("WHERE "); debugBuffer .append("LineCode=") .append("'") .append(lwWholeSaleSummaryDto.getLineCode()) .append("' AND "); debugBuffer .append("StatMonth=") .append("'") .append(lwWholeSaleSummaryDto.getStatMonth()) .append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("LineCode = ? And "); buffer.append("StatMonth = ?"); dbManager.prepareStatement(buffer.toString()); // 设置更新字段; dbManager.setString(1, lwWholeSaleSummaryDto.getPowerClass()); dbManager.setDouble(2, lwWholeSaleSummaryDto.getElectricQuantity()); dbManager.setDouble(3, lwWholeSaleSummaryDto.getPointerQuantity()); dbManager.setDouble(4, lwWholeSaleSummaryDto.getSanXiaFee()); dbManager.setDouble(5, lwWholeSaleSummaryDto.getSurcharge()); dbManager.setDouble(6, lwWholeSaleSummaryDto.getSumFee()); dbManager.setString(7, lwWholeSaleSummaryDto.getValidStatus()); dbManager.setString(8, lwWholeSaleSummaryDto.getFlag()); dbManager.setString(9, lwWholeSaleSummaryDto.getRemark()); dbManager.setDouble(10, lwWholeSaleSummaryDto.getTransLoss()); dbManager.setDouble(11, lwWholeSaleSummaryDto.getLineLoss()); dbManager.setDouble(12, lwWholeSaleSummaryDto.getUnPointerQuantity()); dbManager.setDouble(13, lwWholeSaleSummaryDto.getRateCode()); dbManager.setDouble(14, lwWholeSaleSummaryDto.getAdjustRate()); dbManager.setDouble(15, lwWholeSaleSummaryDto.getFarmUseScale()); dbManager.setDouble(16, lwWholeSaleSummaryDto.getFarmUsePrice()); dbManager.setDouble(17, lwWholeSaleSummaryDto.getFarmUseQuantity()); dbManager.setDouble(18, lwWholeSaleSummaryDto.getFarmUseFee()); dbManager.setDouble(19, lwWholeSaleSummaryDto.getProductScale()); dbManager.setDouble(20, lwWholeSaleSummaryDto.getProductPrice()); dbManager.setDouble(21, lwWholeSaleSummaryDto.getProductQuantity()); dbManager.setDouble(22, lwWholeSaleSummaryDto.getProductFee()); dbManager.setDouble(23, lwWholeSaleSummaryDto.getDenizenScale()); dbManager.setDouble(24, lwWholeSaleSummaryDto.getDenizenPrice()); dbManager.setDouble(25, lwWholeSaleSummaryDto.getDenizenQuantity()); dbManager.setDouble(26, lwWholeSaleSummaryDto.getDenizenFee()); dbManager.setDouble(27, lwWholeSaleSummaryDto.getUnDenizenScale()); dbManager.setDouble(28, lwWholeSaleSummaryDto.getUnDenizenPrice()); dbManager.setDouble(29, lwWholeSaleSummaryDto.getUnDenizenQuantity()); dbManager.setDouble(30, lwWholeSaleSummaryDto.getUnDenizenFee()); dbManager.setDouble(31, lwWholeSaleSummaryDto.getIndustryScale()); dbManager.setDouble(32, lwWholeSaleSummaryDto.getIndustryPrice()); dbManager.setDouble(33, lwWholeSaleSummaryDto.getIndustryQuantity()); dbManager.setDouble(34, lwWholeSaleSummaryDto.getIndustryFee()); dbManager.setDouble(35, lwWholeSaleSummaryDto.getBizScale()); dbManager.setDouble(36, lwWholeSaleSummaryDto.getBizPrice()); dbManager.setDouble(37, lwWholeSaleSummaryDto.getBizQuantity()); dbManager.setDouble(38, lwWholeSaleSummaryDto.getBizFee()); dbManager.setDouble(39, lwWholeSaleSummaryDto.getPowerRateFee()); dbManager.setString(40, lwWholeSaleSummaryDto.getUpCompany()); dbManager.setDouble(41, lwWholeSaleSummaryDto.getPowerFee()); dbManager.setString(42, lwWholeSaleSummaryDto.getInputDate()); dbManager.setString(43, lwWholeSaleSummaryDto.getKv()); dbManager.setString(44, lwWholeSaleSummaryDto.getWholesaletype()); dbManager.setDouble(45, lwWholeSaleSummaryDto.getWorkNum()); dbManager.setDouble(46, lwWholeSaleSummaryDto.getUnWorkNum()); dbManager.setDouble(47, lwWholeSaleSummaryDto.getOtherSurcharge()); dbManager.setString(48, lwWholeSaleSummaryDto.getDifferenceQuantity()); dbManager.setDouble(49, lwWholeSaleSummaryDto.getUnTransLoss()); dbManager.setDouble(50, lwWholeSaleSummaryDto.getUnLineLoss()); // 设置条件字段; dbManager.setString(51, lwWholeSaleSummaryDto.getLineCode()); dbManager.setString(52, lwWholeSaleSummaryDto.getStatMonth()); dbManager.executePreparedUpdate(); }
/** * 插入一条数据 * * @param lwWholeSaleSummaryDto lwWholeSaleSummaryDto * @throws Exception */ public void insert(LwWholeSaleSummaryDto lwWholeSaleSummaryDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("INSERT INTO LwWholeSaleSummary ("); buffer.append("LineCode,"); buffer.append("StatMonth,"); buffer.append("PowerClass,"); buffer.append("ElectricQuantity,"); buffer.append("PointerQuantity,"); buffer.append("SanXiaFee,"); buffer.append("Surcharge,"); buffer.append("SumFee,"); buffer.append("ValidStatus,"); buffer.append("Flag,"); buffer.append("Remark,"); buffer.append("TransLoss,"); buffer.append("LineLoss,"); buffer.append("UnPointerQuantity,"); buffer.append("RateCode,"); buffer.append("AdjustRate,"); buffer.append("FarmUseScale,"); buffer.append("FarmUsePrice,"); buffer.append("FarmUseQuantity,"); buffer.append("FarmUseFee,"); buffer.append("ProductScale,"); buffer.append("ProductPrice,"); buffer.append("ProductQuantity,"); buffer.append("ProductFee,"); buffer.append("DenizenScale,"); buffer.append("DenizenPrice,"); buffer.append("DenizenQuantity,"); buffer.append("DenizenFee,"); buffer.append("UnDenizenScale,"); buffer.append("UnDenizenPrice,"); buffer.append("UnDenizenQuantity,"); buffer.append("UnDenizenFee,"); buffer.append("IndustryScale,"); buffer.append("IndustryPrice,"); buffer.append("IndustryQuantity,"); buffer.append("IndustryFee,"); buffer.append("BizScale,"); buffer.append("BizPrice,"); buffer.append("BizQuantity,"); buffer.append("BizFee,"); buffer.append("PowerRateFee,"); buffer.append("UpCompany,"); buffer.append("PowerFee,"); buffer.append("InputDate,"); buffer.append("Kv,"); buffer.append("Wholesaletype,"); buffer.append("WorkNum,"); buffer.append("UnWorkNum,"); buffer.append("OtherSurcharge,"); buffer.append("DifferenceQuantity,"); buffer.append("UnTransLoss,"); buffer.append("UnLineLoss "); buffer.append(") "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("VALUES("); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getLineCode()).append("',"); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getStatMonth()).append("',"); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getPowerClass()).append("',"); debugBuffer.append("").append(lwWholeSaleSummaryDto.getElectricQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getPointerQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getSanXiaFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getSurcharge()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getSumFee()).append(","); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getValidStatus()).append("',"); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getFlag()).append("',"); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getRemark()).append("',"); debugBuffer.append("").append(lwWholeSaleSummaryDto.getTransLoss()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getLineLoss()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnPointerQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getRateCode()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getAdjustRate()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getFarmUseScale()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getFarmUsePrice()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getFarmUseQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getFarmUseFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getProductScale()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getProductPrice()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getProductQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getProductFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getDenizenScale()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getDenizenPrice()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getDenizenQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getDenizenFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnDenizenScale()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnDenizenPrice()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnDenizenQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnDenizenFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getIndustryScale()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getIndustryPrice()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getIndustryQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getIndustryFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getBizScale()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getBizPrice()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getBizQuantity()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getBizFee()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getPowerRateFee()).append(","); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getUpCompany()).append("',"); debugBuffer.append("").append(lwWholeSaleSummaryDto.getPowerFee()).append(","); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getInputDate()).append("',"); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getKv()).append("',"); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getWholesaletype()).append("',"); debugBuffer.append("").append(lwWholeSaleSummaryDto.getWorkNum()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnWorkNum()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getOtherSurcharge()).append(","); debugBuffer.append("'").append(lwWholeSaleSummaryDto.getDifferenceQuantity()).append("',"); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnTransLoss()).append(","); debugBuffer.append("").append(lwWholeSaleSummaryDto.getUnLineLoss()).append(")"); logger.debug(debugBuffer.toString()); } buffer.append( "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); dbManager.prepareStatement(buffer.toString()); dbManager.setString(1, lwWholeSaleSummaryDto.getLineCode()); dbManager.setString(2, lwWholeSaleSummaryDto.getStatMonth()); dbManager.setString(3, lwWholeSaleSummaryDto.getPowerClass()); dbManager.setDouble(4, lwWholeSaleSummaryDto.getElectricQuantity()); dbManager.setDouble(5, lwWholeSaleSummaryDto.getPointerQuantity()); dbManager.setDouble(6, lwWholeSaleSummaryDto.getSanXiaFee()); dbManager.setDouble(7, lwWholeSaleSummaryDto.getSurcharge()); dbManager.setDouble(8, lwWholeSaleSummaryDto.getSumFee()); dbManager.setString(9, lwWholeSaleSummaryDto.getValidStatus()); dbManager.setString(10, lwWholeSaleSummaryDto.getFlag()); dbManager.setString(11, lwWholeSaleSummaryDto.getRemark()); dbManager.setDouble(12, lwWholeSaleSummaryDto.getTransLoss()); dbManager.setDouble(13, lwWholeSaleSummaryDto.getLineLoss()); dbManager.setDouble(14, lwWholeSaleSummaryDto.getUnPointerQuantity()); dbManager.setDouble(15, lwWholeSaleSummaryDto.getRateCode()); dbManager.setDouble(16, lwWholeSaleSummaryDto.getAdjustRate()); dbManager.setDouble(17, lwWholeSaleSummaryDto.getFarmUseScale()); dbManager.setDouble(18, lwWholeSaleSummaryDto.getFarmUsePrice()); dbManager.setDouble(19, lwWholeSaleSummaryDto.getFarmUseQuantity()); dbManager.setDouble(20, lwWholeSaleSummaryDto.getFarmUseFee()); dbManager.setDouble(21, lwWholeSaleSummaryDto.getProductScale()); dbManager.setDouble(22, lwWholeSaleSummaryDto.getProductPrice()); dbManager.setDouble(23, lwWholeSaleSummaryDto.getProductQuantity()); dbManager.setDouble(24, lwWholeSaleSummaryDto.getProductFee()); dbManager.setDouble(25, lwWholeSaleSummaryDto.getDenizenScale()); dbManager.setDouble(26, lwWholeSaleSummaryDto.getDenizenPrice()); dbManager.setDouble(27, lwWholeSaleSummaryDto.getDenizenQuantity()); dbManager.setDouble(28, lwWholeSaleSummaryDto.getDenizenFee()); dbManager.setDouble(29, lwWholeSaleSummaryDto.getUnDenizenScale()); dbManager.setDouble(30, lwWholeSaleSummaryDto.getUnDenizenPrice()); dbManager.setDouble(31, lwWholeSaleSummaryDto.getUnDenizenQuantity()); dbManager.setDouble(32, lwWholeSaleSummaryDto.getUnDenizenFee()); dbManager.setDouble(33, lwWholeSaleSummaryDto.getIndustryScale()); dbManager.setDouble(34, lwWholeSaleSummaryDto.getIndustryPrice()); dbManager.setDouble(35, lwWholeSaleSummaryDto.getIndustryQuantity()); dbManager.setDouble(36, lwWholeSaleSummaryDto.getIndustryFee()); dbManager.setDouble(37, lwWholeSaleSummaryDto.getBizScale()); dbManager.setDouble(38, lwWholeSaleSummaryDto.getBizPrice()); dbManager.setDouble(39, lwWholeSaleSummaryDto.getBizQuantity()); dbManager.setDouble(40, lwWholeSaleSummaryDto.getBizFee()); dbManager.setDouble(41, lwWholeSaleSummaryDto.getPowerRateFee()); dbManager.setString(42, lwWholeSaleSummaryDto.getUpCompany()); dbManager.setDouble(43, lwWholeSaleSummaryDto.getPowerFee()); dbManager.setString(44, lwWholeSaleSummaryDto.getInputDate()); dbManager.setString(45, lwWholeSaleSummaryDto.getKv()); dbManager.setString(46, lwWholeSaleSummaryDto.getWholesaletype()); dbManager.setDouble(47, lwWholeSaleSummaryDto.getWorkNum()); dbManager.setDouble(48, lwWholeSaleSummaryDto.getUnWorkNum()); dbManager.setDouble(49, lwWholeSaleSummaryDto.getOtherSurcharge()); dbManager.setString(50, lwWholeSaleSummaryDto.getDifferenceQuantity()); dbManager.setDouble(51, lwWholeSaleSummaryDto.getUnTransLoss()); dbManager.setDouble(52, lwWholeSaleSummaryDto.getUnLineLoss()); dbManager.executePreparedUpdate(); }
static String dirForFqcn(String fqcn) { int last_dot = fqcn.lastIndexOf('.'); StringBuffer sb = new StringBuffer(fqcn.substring(0, last_dot + 1)); for (int i = 0, len = sb.length(); i < len; ++i) if (sb.charAt(i) == '.') sb.setCharAt(i, '/'); return sb.toString(); }
public void runReplicate() throws InterruptedException { if (verbose) log.append("Started at " + Calendar.getInstance().getTime() + "\r\n"); Connection connectionFrom = null; Connection connectionTo = null; try { connectionFrom = providerI.getConnection(dbFrom); connectionTo = providerI.getConnection(dbTo); PreparedStatement preparedStatementFrom = null; PreparedStatement preparedStatementTo = null; ResultSet resultSet = null; for (Iterator<HashMap<String, String>> HashMapIterator = tables.iterator(); HashMapIterator.hasNext(); ) { try { HashMap<String, String> h = HashMapIterator.next(); String name = h.get("name"); String name2 = h.get("name2"); String where1 = h.get("where1"); String where2 = h.get("where2"); if (verbose) log.append("Replicating " + dbFrom + "/" + name + " to " + dbTo + "/" + name2 + "\r\n"); preparedStatementFrom = connectionFrom.prepareStatement("select * from " + name + " WHERE 1=1 " + where1); boolean b = preparedStatementFrom.execute(); HashMap meta = new HashMap(); // 1. find all ids from DB1 ArrayList db1 = new ArrayList(); String nullMark = "____NULL"; if (b) { resultSet = preparedStatementFrom.getResultSet(); ResultSetMetaData setMetaData = resultSet.getMetaData(); for (int i = 1; i <= setMetaData.getColumnCount(); i++) { meta.put( setMetaData.getColumnLabel(i).toLowerCase(), setMetaData.getColumnClassName(i)); } while (resultSet.next()) { HashMap results = new HashMap(); for (int i = 1; i <= setMetaData.getColumnCount(); i++) { String columnName = setMetaData.getColumnLabel(i).toLowerCase(); Object o = resultSet.getObject(i); if (o != null) { results.put(columnName, o); } else { results.put(columnName + nullMark, nullMark); } } db1.add(results); } resultSet.close(); } else { log.append("Couldn't execute select from " + dbFrom + "/" + name + " /r/n"); return; } StringBuffer allIds = new StringBuffer(); HashMap records1 = new HashMap(); HashMap toInsert = new HashMap(); HashMap toUpdate = new HashMap(); for (Iterator iterator = db1.iterator(); iterator.hasNext(); ) { HashMap record = (HashMap) iterator.next(); if (allIds.length() != 0) { allIds.append(","); } allIds.append(record.get("id")); records1.put(record.get("id"), record); } toInsert.putAll(records1); // 2. find all ids to delete in DB2; if (allIds.length() > 0) { preparedStatementTo = connectionTo.prepareStatement( "delete from " + name2 + " where id not in (" + allIds.toString() + ")" + where2); if (verbose) log.append( "deleted from " + dbTo + "/" + name2 + " " + preparedStatementTo.executeUpdate() + " records;\r\n"); } else { if (verbose) log.append( "No records in " + dbFrom + "/" + name + ", nothing to delete in " + dbTo + "/" + name2 + " ;\r\n"); } // 3. find all ids from DB2; preparedStatementTo = connectionTo.prepareStatement("select * from " + name2 + " WHERE 1=1 " + where2); b = preparedStatementTo.execute(); HashMap meta2 = new HashMap(); ArrayList db2 = new ArrayList(); if (b) { resultSet = preparedStatementTo.getResultSet(); ResultSetMetaData setMetaData = resultSet.getMetaData(); for (int i = 1; i <= setMetaData.getColumnCount(); i++) { meta2.put( setMetaData.getColumnLabel(i).toLowerCase(), setMetaData.getColumnClassName(i)); } while (resultSet.next()) { HashMap results = new HashMap(); for (int i = 1; i <= setMetaData.getColumnCount(); i++) { String columnName = setMetaData.getColumnLabel(i).toLowerCase(); Object o = resultSet.getObject(i); if (o != null) { results.put(columnName, o); } else { results.put(columnName + nullMark, nullMark); } } db2.add(results); } } else { log.append("Couldn't execute select from " + dbTo + "/" + name2 + " /r/n"); return; } // compare meta-data; { HashMap temp = new HashMap(); { temp.putAll(meta); Set set = meta2.keySet(); for (Iterator iteratorSet = set.iterator(); iteratorSet.hasNext(); ) { Object o = iteratorSet.next(); if (meta.containsKey(o)) { if (meta.get(o).equals(meta2.get(o))) { temp.remove(o); } } else { log.append("ERROR: Meta data not equals! \r\n"); log.append(o + "\t" + temp.get(o) + " not present in table " + name + "\r\n"); } } } if (!temp.isEmpty()) { log.append("ERROR: Meta data not equals! \r\n"); Set set = temp.keySet(); for (Iterator iteratorSet = set.iterator(); iteratorSet.hasNext(); ) { Object o = iteratorSet.next(); log.append(o + "\t" + temp.get(o) + " != " + meta2.get(o) + "\r\n"); } return; } } for (Iterator iterator = db2.iterator(); iterator.hasNext(); ) { HashMap db2Record = (HashMap) iterator.next(); if (toInsert.containsKey(db2Record.get("id"))) { HashMap db1Record = (HashMap) toInsert.get(db2Record.get("id")); boolean equal = true; Set set = meta2.keySet(); for (Iterator iteratorSet = set.iterator(); equal && iteratorSet.hasNext(); ) { String columnName2 = (String) iteratorSet.next(); if (db2Record.containsKey(columnName2 + nullMark) || db1Record.containsKey(columnName2 + nullMark)) { equal = db2Record.containsKey(columnName2 + nullMark) && db1Record.containsKey(columnName2 + nullMark); } else { // checking not-null; equal = equalRecords(db1Record.get(columnName2), db2Record.get(columnName2)); } } if (!equal) { toUpdate.put(db2Record.get("id"), toInsert.get(db2Record.get("id"))); } toInsert.remove(db2Record.get("id")); } else { // this case shouldn't happen at all, since we've deleted all such records } } log.append( "Found " + toUpdate.size() + " to update, and " + toInsert.size() + " to insert.\r\n"); int totalUpdated = 0; // 4. calculate all to update in DB2 if (!toUpdate.isEmpty()) { Set set = toUpdate.keySet(); for (Iterator iteratorSet = set.iterator(); iteratorSet.hasNext(); ) { StringBuffer sql = new StringBuffer(); Object id = iteratorSet.next(); HashMap r = (HashMap) toUpdate.get(id); sql.append("UPDATE " + name2 + " SET "); StringBuffer values = new StringBuffer(); Set en = meta2.keySet(); for (Iterator iteratorSetEn = en.iterator(); iteratorSetEn.hasNext(); ) { Object o = iteratorSetEn.next(); if (!o.equals("id")) { if (values.length() != 0) { values.append(","); } Object quote = dbQuotes.get(dbToType); if (quote == null) { quote = ""; } values.append(quote).append(o).append(quote); values.append(" = ? "); } } values.append(" WHERE id = '" + r.get("id") + "';"); PreparedStatement statement = connectionTo.prepareStatement(sql.toString() + values.toString()); en = meta2.keySet(); int i = 0; for (Iterator iteratorSetEn = en.iterator(); iteratorSetEn.hasNext(); ) { Object o = iteratorSetEn.next(); if (!o.equals("id")) { i++; statement.setObject(i, r.get(o)); } } try { totalUpdated += statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); log.append("Error occured: " + e + "\r\n"); } } } if (verbose) log.append("Updated " + totalUpdated + " records.\r\n"); // 4. calculate all to insert to DB2 if (!toInsert.isEmpty()) { StringBuffer header = new StringBuffer(); if (header.length() == 0) { header.append(" INSERT INTO " + name2 + " ("); StringBuffer columns = new StringBuffer(); Set en = meta2.keySet(); for (Iterator iteratorSetEn = en.iterator(); iteratorSetEn.hasNext(); ) { Object o = iteratorSetEn.next(); if (columns.length() != 0) { columns.append(","); } Object quote = dbQuotes.get(dbToType); if (quote == null) { quote = ""; } columns.append(quote).append(o).append(quote); } header.append(columns.toString()); header.append(") VALUES "); } Set enumeration = toInsert.keySet(); for (Iterator iteratorSetX = enumeration.iterator(); iteratorSetX.hasNext(); ) { Object id = iteratorSetX.next(); HashMap r = (HashMap) toInsert.get(id); StringBuffer values = new StringBuffer(); if (values.length() != 0) { values.append(","); } values.append("("); StringBuffer columns = new StringBuffer(); Set en = meta2.keySet(); for (Iterator iteratorSetEn = en.iterator(); iteratorSetEn.hasNext(); ) { Object o = iteratorSetEn.next(); if (columns.length() != 0) { columns.append(","); } columns.append(" ? "); } values.append(columns.toString()); values.append(");"); PreparedStatement statement = connectionTo.prepareStatement(header.toString() + values.toString()); en = meta2.keySet(); int i = 0; for (Iterator iteratorSetEn = en.iterator(); iteratorSetEn.hasNext(); ) { Object o = iteratorSetEn.next(); i++; statement.setObject(i, r.get(o)); } statement.execute(); } } if (verbose) log.append("Replication finished OK.\r\n"); } catch (Exception e) { log.append("Some error occured: " + e + "\r\n"); log.append(e.getMessage() + "\r\n"); e.printStackTrace(); } } } catch (Exception e) { log.append("Error with query = " + e); log.append(e.getMessage()); return; } finally { try { if (connectionFrom != null && !connectionFrom.isClosed()) { connectionFrom.close(); } } catch (SQLException e) { e.printStackTrace(); } try { if (connectionTo != null && !connectionTo.isClosed()) { connectionTo.close(); } } catch (SQLException e) { e.printStackTrace(); } } if (verbose) log.append("Ended at " + Calendar.getInstance().getTime()); }
/** * 按主键查找一条数据 * * @param userNo 户号 * @param statMonth 账期 * @return LwTownIndicatorDto * @throws Exception */ public LwTownIndicatorDto findByPrimaryKey(String userNo, String statMonth) throws Exception { StringBuffer buffer = new StringBuffer(200); // 拼SQL语句 buffer.append("SELECT "); buffer.append("UserNo,"); buffer.append("UserName,"); buffer.append("Address,"); buffer.append("ReadDate,"); buffer.append("StatMonth,"); buffer.append("ThisWorkNum,"); buffer.append("MidWorkNum,"); buffer.append("LastWorkNum,"); buffer.append("Rate,"); buffer.append("ReadQuantity,"); buffer.append("ExcepQuantity,"); buffer.append("ChgAmmeterQuantity,"); buffer.append("CompensateQuantity,"); buffer.append("AppendCalQuantity,"); buffer.append("TranferLossQuantity,"); buffer.append("PeoplePrice,"); buffer.append("NotPeoplePrice,"); buffer.append("FarmPrice,"); buffer.append("ProducePrice,"); buffer.append("BusinessPrice,"); buffer.append("Voltlevel,"); buffer.append("IndustryPrice,"); buffer.append("ValidStatus,"); buffer.append("Flag,"); buffer.append("Remark,"); buffer.append("InputDate "); buffer.append("FROM LwTownIndicator "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("WHERE "); debugBuffer.append("UserNo=").append("'").append(userNo).append("' AND "); debugBuffer.append("StatMonth=").append("'").append(statMonth).append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("UserNo = ? And "); buffer.append("StatMonth = ?"); dbManager.prepareStatement(buffer.toString()); // 设置条件字段; dbManager.setString(1, userNo); dbManager.setString(2, statMonth); ResultSet resultSet = dbManager.executePreparedQuery(); LwTownIndicatorDto lwTownIndicatorDto = null; if (resultSet.next()) { lwTownIndicatorDto = new LwTownIndicatorDto(); lwTownIndicatorDto.setUserNo(dbManager.getString(resultSet, 1)); lwTownIndicatorDto.setUserName(dbManager.getString(resultSet, 2)); lwTownIndicatorDto.setAddress(dbManager.getString(resultSet, 3)); lwTownIndicatorDto.setReadDate(dbManager.getString(resultSet, 4)); lwTownIndicatorDto.setStatMonth(dbManager.getString(resultSet, 5)); lwTownIndicatorDto.setThisWorkNum(dbManager.getDouble(resultSet, 6)); lwTownIndicatorDto.setMidWorkNum(dbManager.getDouble(resultSet, 7)); lwTownIndicatorDto.setLastWorkNum(dbManager.getDouble(resultSet, 8)); lwTownIndicatorDto.setRate(dbManager.getDouble(resultSet, 9)); lwTownIndicatorDto.setReadQuantity(dbManager.getDouble(resultSet, 10)); lwTownIndicatorDto.setExcepQuantity(dbManager.getDouble(resultSet, 11)); lwTownIndicatorDto.setChgAmmeterQuantity(dbManager.getDouble(resultSet, 12)); lwTownIndicatorDto.setCompensateQuantity(dbManager.getDouble(resultSet, 13)); lwTownIndicatorDto.setAppendCalQuantity(dbManager.getLong(resultSet, 14)); lwTownIndicatorDto.setTranferLossQuantity(dbManager.getLong(resultSet, 15)); lwTownIndicatorDto.setPeoplePrice(dbManager.getDouble(resultSet, 16)); lwTownIndicatorDto.setNotPeoplePrice(dbManager.getDouble(resultSet, 17)); lwTownIndicatorDto.setFarmPrice(dbManager.getDouble(resultSet, 18)); lwTownIndicatorDto.setProducePrice(dbManager.getDouble(resultSet, 19)); lwTownIndicatorDto.setBusinessPrice(dbManager.getDouble(resultSet, 20)); lwTownIndicatorDto.setVoltlevel(dbManager.getInt(resultSet, 21)); lwTownIndicatorDto.setIndustryPrice(dbManager.getDouble(resultSet, 22)); lwTownIndicatorDto.setValidStatus(dbManager.getString(resultSet, 23)); lwTownIndicatorDto.setFlag(dbManager.getString(resultSet, 24)); lwTownIndicatorDto.setRemark(dbManager.getString(resultSet, 25)); lwTownIndicatorDto.setInputDate(dbManager.getString(resultSet, 26)); } resultSet.close(); return lwTownIndicatorDto; }
/** * 插入一条数据 * * @param lwTownIndicatorDto lwTownIndicatorDto * @throws Exception */ public void insert(LwTownIndicatorDto lwTownIndicatorDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("INSERT INTO LwTownIndicator ("); buffer.append("UserNo,"); buffer.append("UserName,"); buffer.append("Address,"); buffer.append("ReadDate,"); buffer.append("StatMonth,"); buffer.append("ThisWorkNum,"); buffer.append("MidWorkNum,"); buffer.append("LastWorkNum,"); buffer.append("Rate,"); buffer.append("ReadQuantity,"); buffer.append("ExcepQuantity,"); buffer.append("ChgAmmeterQuantity,"); buffer.append("CompensateQuantity,"); buffer.append("AppendCalQuantity,"); buffer.append("TranferLossQuantity,"); buffer.append("PeoplePrice,"); buffer.append("NotPeoplePrice,"); buffer.append("FarmPrice,"); buffer.append("ProducePrice,"); buffer.append("BusinessPrice,"); buffer.append("Voltlevel,"); buffer.append("IndustryPrice,"); buffer.append("ValidStatus,"); buffer.append("Flag,"); buffer.append("Remark,"); buffer.append("InputDate "); buffer.append(") "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append(buffer.toString()); debugBuffer.append("VALUES("); debugBuffer.append("'").append(lwTownIndicatorDto.getUserNo()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getUserName()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getAddress()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getReadDate()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getStatMonth()).append("',"); debugBuffer.append("").append(lwTownIndicatorDto.getThisWorkNum()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getMidWorkNum()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getLastWorkNum()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getRate()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getReadQuantity()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getExcepQuantity()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getChgAmmeterQuantity()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getCompensateQuantity()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getAppendCalQuantity()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getTranferLossQuantity()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getPeoplePrice()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getNotPeoplePrice()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getFarmPrice()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getProducePrice()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getBusinessPrice()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getVoltlevel()).append(","); debugBuffer.append("").append(lwTownIndicatorDto.getIndustryPrice()).append(","); debugBuffer.append("'").append(lwTownIndicatorDto.getValidStatus()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getFlag()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getRemark()).append("',"); debugBuffer.append("'").append(lwTownIndicatorDto.getInputDate()).append("')"); logger.debug(debugBuffer.toString()); } buffer.append("VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); dbManager.prepareStatement(buffer.toString()); dbManager.setString(1, lwTownIndicatorDto.getUserNo()); dbManager.setString(2, lwTownIndicatorDto.getUserName()); dbManager.setString(3, lwTownIndicatorDto.getAddress()); dbManager.setString(4, lwTownIndicatorDto.getReadDate()); dbManager.setString(5, lwTownIndicatorDto.getStatMonth()); dbManager.setDouble(6, lwTownIndicatorDto.getThisWorkNum()); dbManager.setDouble(7, lwTownIndicatorDto.getMidWorkNum()); dbManager.setDouble(8, lwTownIndicatorDto.getLastWorkNum()); dbManager.setDouble(9, lwTownIndicatorDto.getRate()); dbManager.setDouble(10, lwTownIndicatorDto.getReadQuantity()); dbManager.setDouble(11, lwTownIndicatorDto.getExcepQuantity()); dbManager.setDouble(12, lwTownIndicatorDto.getChgAmmeterQuantity()); dbManager.setDouble(13, lwTownIndicatorDto.getCompensateQuantity()); dbManager.setLong(14, lwTownIndicatorDto.getAppendCalQuantity()); dbManager.setLong(15, lwTownIndicatorDto.getTranferLossQuantity()); dbManager.setDouble(16, lwTownIndicatorDto.getPeoplePrice()); dbManager.setDouble(17, lwTownIndicatorDto.getNotPeoplePrice()); dbManager.setDouble(18, lwTownIndicatorDto.getFarmPrice()); dbManager.setDouble(19, lwTownIndicatorDto.getProducePrice()); dbManager.setDouble(20, lwTownIndicatorDto.getBusinessPrice()); dbManager.setInt(21, lwTownIndicatorDto.getVoltlevel()); dbManager.setDouble(22, lwTownIndicatorDto.getIndustryPrice()); dbManager.setString(23, lwTownIndicatorDto.getValidStatus()); dbManager.setString(24, lwTownIndicatorDto.getFlag()); dbManager.setString(25, lwTownIndicatorDto.getRemark()); dbManager.setString(26, lwTownIndicatorDto.getInputDate()); dbManager.executePreparedUpdate(); }
/** * 按主键更新一条数据(主键本身无法变更) * * @param lwTownIndicatorDto lwTownIndicatorDto * @throws Exception */ public void update(LwTownIndicatorDto lwTownIndicatorDto) throws Exception { StringBuffer buffer = new StringBuffer(200); buffer.append("UPDATE LwTownIndicator SET "); buffer.append("UserName = ?, "); buffer.append("Address = ?, "); buffer.append("ReadDate = ?, "); buffer.append("ThisWorkNum = ?, "); buffer.append("MidWorkNum = ?, "); buffer.append("LastWorkNum = ?, "); buffer.append("Rate = ?, "); buffer.append("ReadQuantity = ?, "); buffer.append("ExcepQuantity = ?, "); buffer.append("ChgAmmeterQuantity = ?, "); buffer.append("CompensateQuantity = ?, "); buffer.append("AppendCalQuantity = ?, "); buffer.append("TranferLossQuantity = ?, "); buffer.append("PeoplePrice = ?, "); buffer.append("NotPeoplePrice = ?, "); buffer.append("FarmPrice = ?, "); buffer.append("ProducePrice = ?, "); buffer.append("BusinessPrice = ?, "); buffer.append("Voltlevel = ?, "); buffer.append("IndustryPrice = ?, "); buffer.append("ValidStatus = ?, "); buffer.append("Flag = ?, "); buffer.append("Remark = ?, "); buffer.append("InputDate = ? "); if (logger.isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(buffer.length() * 4); debugBuffer.append("UPDATE LwTownIndicator SET "); debugBuffer.append("UserName = '******', "); debugBuffer.append("Address = '" + lwTownIndicatorDto.getAddress() + "', "); debugBuffer.append("ReadDate = '" + lwTownIndicatorDto.getReadDate() + "', "); debugBuffer.append("ThisWorkNum = " + lwTownIndicatorDto.getThisWorkNum() + ", "); debugBuffer.append("MidWorkNum = " + lwTownIndicatorDto.getMidWorkNum() + ", "); debugBuffer.append("LastWorkNum = " + lwTownIndicatorDto.getLastWorkNum() + ", "); debugBuffer.append("Rate = " + lwTownIndicatorDto.getRate() + ", "); debugBuffer.append("ReadQuantity = " + lwTownIndicatorDto.getReadQuantity() + ", "); debugBuffer.append("ExcepQuantity = " + lwTownIndicatorDto.getExcepQuantity() + ", "); debugBuffer.append( "ChgAmmeterQuantity = " + lwTownIndicatorDto.getChgAmmeterQuantity() + ", "); debugBuffer.append( "CompensateQuantity = " + lwTownIndicatorDto.getCompensateQuantity() + ", "); debugBuffer.append("AppendCalQuantity = " + lwTownIndicatorDto.getAppendCalQuantity() + ", "); debugBuffer.append( "TranferLossQuantity = " + lwTownIndicatorDto.getTranferLossQuantity() + ", "); debugBuffer.append("PeoplePrice = " + lwTownIndicatorDto.getPeoplePrice() + ", "); debugBuffer.append("NotPeoplePrice = " + lwTownIndicatorDto.getNotPeoplePrice() + ", "); debugBuffer.append("FarmPrice = " + lwTownIndicatorDto.getFarmPrice() + ", "); debugBuffer.append("ProducePrice = " + lwTownIndicatorDto.getProducePrice() + ", "); debugBuffer.append("BusinessPrice = " + lwTownIndicatorDto.getBusinessPrice() + ", "); debugBuffer.append("Voltlevel = " + lwTownIndicatorDto.getVoltlevel() + ", "); debugBuffer.append("IndustryPrice = " + lwTownIndicatorDto.getIndustryPrice() + ", "); debugBuffer.append("ValidStatus = '" + lwTownIndicatorDto.getValidStatus() + "', "); debugBuffer.append("Flag = '" + lwTownIndicatorDto.getFlag() + "', "); debugBuffer.append("Remark = '" + lwTownIndicatorDto.getRemark() + "', "); debugBuffer.append("InputDate = '" + lwTownIndicatorDto.getInputDate() + "' "); debugBuffer.append("WHERE "); debugBuffer .append("UserNo=") .append("'") .append(lwTownIndicatorDto.getUserNo()) .append("' AND "); debugBuffer .append("StatMonth=") .append("'") .append(lwTownIndicatorDto.getStatMonth()) .append("'"); logger.debug(debugBuffer.toString()); } buffer.append("WHERE "); buffer.append("UserNo = ? And "); buffer.append("StatMonth = ?"); dbManager.prepareStatement(buffer.toString()); // 设置更新字段; dbManager.setString(1, lwTownIndicatorDto.getUserName()); dbManager.setString(2, lwTownIndicatorDto.getAddress()); dbManager.setString(3, lwTownIndicatorDto.getReadDate()); dbManager.setDouble(4, lwTownIndicatorDto.getThisWorkNum()); dbManager.setDouble(5, lwTownIndicatorDto.getMidWorkNum()); dbManager.setDouble(6, lwTownIndicatorDto.getLastWorkNum()); dbManager.setDouble(7, lwTownIndicatorDto.getRate()); dbManager.setDouble(8, lwTownIndicatorDto.getReadQuantity()); dbManager.setDouble(9, lwTownIndicatorDto.getExcepQuantity()); dbManager.setDouble(10, lwTownIndicatorDto.getChgAmmeterQuantity()); dbManager.setDouble(11, lwTownIndicatorDto.getCompensateQuantity()); dbManager.setLong(12, lwTownIndicatorDto.getAppendCalQuantity()); dbManager.setLong(13, lwTownIndicatorDto.getTranferLossQuantity()); dbManager.setDouble(14, lwTownIndicatorDto.getPeoplePrice()); dbManager.setDouble(15, lwTownIndicatorDto.getNotPeoplePrice()); dbManager.setDouble(16, lwTownIndicatorDto.getFarmPrice()); dbManager.setDouble(17, lwTownIndicatorDto.getProducePrice()); dbManager.setDouble(18, lwTownIndicatorDto.getBusinessPrice()); dbManager.setInt(19, lwTownIndicatorDto.getVoltlevel()); dbManager.setDouble(20, lwTownIndicatorDto.getIndustryPrice()); dbManager.setString(21, lwTownIndicatorDto.getValidStatus()); dbManager.setString(22, lwTownIndicatorDto.getFlag()); dbManager.setString(23, lwTownIndicatorDto.getRemark()); dbManager.setString(24, lwTownIndicatorDto.getInputDate()); // 设置条件字段; dbManager.setString(25, lwTownIndicatorDto.getUserNo()); dbManager.setString(26, lwTownIndicatorDto.getStatMonth()); dbManager.executePreparedUpdate(); }