【MySql】Java 批量插入数据库addBatch

//addBatch批量插入数据库
public static void insertCommentToMySql(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 block
e1.printStackTrace();
}; String sql = null;
String[] strs=null;
while (it.hasNext()) {
strs = it.next().split("\\|");
//0zid,1zname,2zmid,3ztext,4zsource,5zzan,6ztime
sql="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 block
logger.error(e);
} }

  

上一篇:qt调用js,js调用qt


下一篇:Conversion to Dalvik format failed:Unable toexecute dex: method ID not in [0, 0xffff]: 65536