csdnzlw 2016-03-03 08:11 采纳率: 0%
浏览 5178

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

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条回答 默认 最新

  • Royal_lr 2016-03-03 08:43
    关注

    批处理,,成批的插入

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口