向数据库上批量插入数据的时候 是使用perparedstatement效率好还是用executebatch效率好?

解决方案 »

  1.   

    用perparedstatement:addBatch+executebatch
      

  2.   

    自己写batch程序  赫赫
      

  3.   

    我感觉这样比较好
    insert into values(f1, f2) select f1, f2 from tablename
      

  4.   

    干嘛不perparedstatement+executebatch以前我用过。
    效率上就没测试过
      

  5.   

    这是两种省时间的方式:
    perparedstatement减少了sql编译的时间,如果你的语句为大量固定格式语句,建议使用。
    executebatch减少网络传输时间(通过减少传输次数)。各有优缺不能一概而论
      

  6.   

    两种方式不是一个层次上的,可以一起使用的啊.用PREPARESTATEMENT建立SQL语句,用addBatch+executebatch执行语句,楼主清楚两者的用法没有先??
      

  7.   

    perparedstatement要好多了!速度快!!!!!
      

  8.   

    perparedstatement+executebatch具体怎么用?
      

  9.   

    perparedstatement+executebatch:
    //......
    PreparedStatement ps = cn.preparedStatement(sql);
    String[] fieldList = expItems.split("@");
    String sql ="insert into PATTERNINFO  (CUSTOMER_CODE, DBFIELD) values (?,?) ";
    for (int i = 0; i < fieldList.length; i++) {
      ps.setString(1, customerCode);
      ps.setString(2, fieldList[i]);
      ps.addBatch();
    }
    ps.executeBatch();