单条insert into table value() 13W数据需要执行7小时
变成inert into table value(),(),(),(),()
inert into table value(),(),(),(),()
inert into table value(),(),(),(),()
这样,效率节省N倍 ,13W数据只需要3分钟
@Override public boolean addBRDforList(List<AiResultBai> data) { boolean flag=false; String sql="insert into `ai_result_baidu`(`id`,`data_base_id`,`sentiment`,`positive_prob`,`negative_prob`,`create_time`) values "; //+ "values ( NULL,?,?,?,?,?)"; List<String> sbList = new ArrayList<>();//存储sql StringBuffer sb = new StringBuffer(); DataBaseDao dbd=new DataBaseDaoImpl(); for(int i = 0 ; i < data.size() ; i++) { //对数据进行分析,并得出base_id if(i==0 || i%10==0) { if (sb.toString().length() > 0) {//第一次不会进来 sbList.add(sb.toString()); } sb=new StringBuffer(); sb.append(sql).append("(NULL,"+data.get(i).getData_base_id()+","+data.get(i).getSentiment()+","+data.get(i).getPositive_prob()+","+data.get(i).getNegative_prob()+",'"+data.get(i).getCreate_time()+"'"+")"); }else if(i == data.size() -1) { sb.append(","+"(NULL,"+data.get(i).getData_base_id()+","+data.get(i).getSentiment()+","+data.get(i).getPositive_prob()+","+data.get(i).getNegative_prob()+",'"+data.get(i).getCreate_time()+"'"+")"); sbList.add(sb.toString()); }else { sb.append(","+"(NULL,"+data.get(i).getData_base_id()+","+data.get(i).getSentiment()+","+data.get(i).getPositive_prob()+","+data.get(i).getNegative_prob()+",'"+data.get(i).getCreate_time()+"'"+")"); } } System.out.println(sbList.size()); int j=0; for (String string : sbList) { j++; System.out.println(j+"=="+"sql====="+string); if(this.getconnection()) { this.executeUpdate1(string); } this.clossconnection(); } if(sbList.size()==j) { flag=true; } System.out.println("共有Sql:"+sbList.size()+"条"); return flag; }