csdnzlw
csdnzlw
2016-03-03 08:11

mysql 插入10万条数据 优化效率

  • 优化
  • mysql
public int addTypes(List<taobaoBean> babyList) {

    String sql = "insert into type (typeid,url) values (?,?) ";
    Connection conn = dbhelper.getConnection(driver,url,username,upwd);
    int result  = 0;
    PreparedStatement stmt =null;
    try {
        stmt = conn.prepareStatement(sql);
        for(int i=0;i<babyList.size();i++){
            stmt.setInt(1, babyList.get(i).getTypeId());
            stmt.setString(2, babyList.get(i).getUrl());
            stmt.addBatch();
        }
        stmt.executeBatch();
    } catch (Exception e) {
        e.printStackTrace();
    }finally{
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        dbhelper.closeCon(conn);
    }
    return result;
}

1分钟才插入3000条数据,如何变快。
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐