單條insert into table value() 13W數據須要執行7小時java
變成inert into table value(),(),(),(),()sql
inert into table value(),(),(),(),()app
inert into table value(),(),(),(),()ide
這樣,效率節省N倍 ,13W數據只須要3分鐘this
@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; }