PreparedStatement ps = conn.prepareStatement("insert into t (a, b, c) values(?,?,?)";
while(expression){
a=......;
b=......;
c=.......;
ps.setInt(1,a);
ps.setInt(2,b);
ps.setInt(3,c);
ps.executeUpdate();
}这样做绝对快  http://www.javayou.com

解决方案 »

  1.   

    如果是一次性插入这么多的话,建议你用批量更新!!String preSql = "("insert into t (a, b, c) values(?,?,?)";
    PreparedStatement preStm = con.prepareStatement(preSql);Iterator normalIter = normalSet.iterator();
    while(normalIter.hasNext()) {
    a=......;
    b=......;
    c=.......;
    preStm.setInt(1,a);
    preStm.setInt(2,b);
    preStm.setInt(3,c); preStm.addBatch();
    }preStm.executeBatch();
    con.commit();
      

  2.   

    谢谢楼上两位
    但是两种都试了几次,速度没有什么的提升,跟直接executeUpdate(strsql)一样慢
    有没有其他的好办法啊
      

  3.   

    每个stmt.executeUpdate都用一个新的连接,
    并采用连接池,
    试一试,或许会有提高。
      

  4.   

    a b c 等于什么,如果是其他从数据库里面出来的数据,为什么不insert into...select from