接下来的代码需要修改,如果可以的话,我们可以使用常量文件吗,然后如何将字符串分离到单独的文件中,以便继续循环,从而不影响性能

for (int j = 0; j < subconfigListRLC.size(); j++) {
    StringBuffer sqlQuery = new StringBuffer();
    test = (SubConfigurationDetailsObject) subconfigListRLC.get(j);
    if (test.getFlag().equalsIgnoreCase("T")) {
        sqlQuery = sqlQuery.append("update SUB_CONFIG set TSTED = "
                + test.getSubConfigurationIndexNo() + " , Q_SUB_INDX = 0 "
                + "where BASE_ENG_KEY = '" + test.getBaseEngineKey() + "' "
                + "AND MODEL_YEAR = '" + modelYear + "' "
                + "AND RLHP_LVW = '" + test.getRoadLoadHorsepowerValue() + "' "
                + "AND LVW_TEST_WT_WO_CONT = '" + test.getEtwValue() + "' "
                + "AND INERTIA_WT_CLASS = '" + test.getInertiaWeightClassNo() + "' "
                + "AND TEST_GROUP_ID = " + test.getTestGroupId() + " "
                + "AND ENGINE_CODE = '" + test.getEngineCode() + "' "
                + "AND AXLE_RATIO = '" + test.getAxleRatioValue() + "'");
    } else if (test.getFlag().equalsIgnoreCase("U")) {
        sqlQuery = sqlQuery.append("update SUB_CONFIG set Q_SUB_INDX = "
                + test.getSubConfigurationIndexNo() + " "
                + "where BASE_ENG_KEY = '" + test.getBaseEngineKey() + "' "
                + "AND MODEL_YEAR = '" + modelYear + "' "
                + "AND RLHP_LVW = '" + test.getRoadLoadHorsepowerValue() + "' "
                + "AND LVW_TEST_WT_WO_CONT = '" + test.getEtwValue() + "' "
                + "AND INERTIA_WT_CLASS = '" + test.getInertiaWeightClassNo() + "' "
                + "AND TEST_GROUP_ID = " + test.getTestGroupId() + " "
                + "AND ENGINE_CODE = '" + test.getEngineCode() + "' "
                + "AND AXLE_RATIO = '" + test.getAxleRatioValue() + "'");
    }
    //System.out.println("Query----------->"+sqlQuery.toString());
    processor.getUpdateAccessor().executeUpdateSql(sqlQuery.toString());
}

最佳答案

使用Java PreparedStatement来构建查询。然后,您可以将PreparedStatement的查询字符串存储在属性文件中。在进入循环之前将两个可能的查询字符串读入变量(实际上,您可能要在进入循环之前构建两个PreparedStatements-取决于是否始终同时使用它们)。然后,您可以调用clearParamaters,然后设置新参数,执行,重复。

关于java - 需要修改Imp代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20797752/

10-10 21:49