JDBC批量处理

 1.Statement:提供addBatch(String sql) 和 excuteBatch()方法批量更新数据
                Statement smt=....
               
                smt.addBatch("insert into talbename...");

                smt.addBatch("sql 语句2");

                smt.addBatch("sql 语句3);

                 ................

                smt.executeBatch();                  //批量执行

 

2 .使用PreparedStatement 

                 PreparedStatement    psmt=conn.perparedStatement("insert into tablename values(?)");

                 psmt.setString(0,"aaa");

                 psmt.addBatch();

            
                 psmt.setString(0,"bbb");

                 psmt.addBatch(0,"aaa");

                  ......................

                 psmt.executeBatch();

你可能感兴趣的:(JDBC批量处理)