• Java拼接批量新增SQL语句


    StringBuffer addSql = new StringBuffer(1000);
                int batchSize = 50;
                int executeTime = 0;
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                for (int i=0; i<trackIds.size(); i++) {
                    if(i/batchSize > executeTime) {//50轮执行一次SQL(拷贝数据量太大)
                        String sql = addSql.substring(0, addSql.length() - 1);
                        baseJdbcDao.exceute(sql, null);
                        executeTime++;//执行次数++
                    }
                    if(i%batchSize == 0) {//50轮重新拼接SQL(防止SQL过长)
                        addSql = addSql.delete(0, addSql.length());
                        addSql.append("insert into " + DatabaseConstants.BASE + ".yk_behavior_monitor (TRACK_ID, PROGRAM_ID, " +
                                "BEHAVIOR_ID, ACTION_TOTAL, ACTION_COMPLETED, CREATED_BY, CREATED_DATE, LAST_UPDATED_BY, LAST_UPDATED_DATE, REMOVE_FLAG) values");
                    }
                    for (Integer behaviorId : behaviorIds) {
                        addSql.append("(");
                        addSql.append(trackIds.get(i) + ",");
                        addSql.append(programId + ",");
                        addSql.append(behaviorId + ",");
                        addSql.append("0,0,");
                        addSql.append(user.getUserId() + ",");
                        addSql.append("'" + sdf.format(new Date()) + "',");
                        addSql.append(user.getUserId() + ",");
                        addSql.append("'" + sdf.format(new Date()) + "',");
                        addSql.append("0),");
                    }
                }
                String sql = addSql.substring(0, addSql.length() - 1);
                baseJdbcDao.exceute(sql, null);
  • 相关阅读:
    关于 TIdHttp
    DCEF3 相关资料
    WPF RichTextBox 控件常用方法和属性
    Delphi Data Type to C# Data Type
    获取 CPU 序列号
    Visual Studio 调用 Delphi DLL 会退出的解决方案
    IDHttp的基本用法(转)
    TChromeTabs 优化改进
    java与json转换
    js charAt()方法
  • 原文地址:https://www.cnblogs.com/cocoat/p/5284946.html
Copyright © 2020-2023  润新知