//addbatch BULK Insert Database Public Static voidInsertcommenttomysql (set<string>commentlist) {Iterator<String> it =Commentlist.iterator (); Statement St=NULL; Try{St=dbconnection.getconnection (dbname,dbuser,dbpwd). createstatement (); } Catch(SQLException E1) {//TODO auto-generated Catch blockE1.printstacktrace (); }; String SQL=NULL; String[] STRs=NULL; while(It.hasnext ()) {STRs= It.next (). Split ("\\|"); //0zid,1zname,2zmid,3ztext,4zsource,5zzan,6ztimeSql= "INSERT into weibo_comment (uid,name,mid,text,source,zan,time) VALUES ('" +strs[0]+ "', '" +strs[1]+ "', '" +strs[2]+ " ', ' "+strs[3]+" ', ' "+strs[4]+" ', ' "+strs[5]+" ', ' "+strs[6]+" ') on DUPLICATE KEY UPDATE updatetime=now () ";//System.out.println (SQL); Try{st.addbatch (SQL); } Catch(SQLException e) {e.printstacktrace (); } } Try{st.executebatch (); St.clearbatch (); St.close (); } Catch(SQLException e) {//TODO auto-generated Catch blockLogger.error (e); } }
Java MYSQL BULK Insert Database Addbatch