JDBC06 其他操作及批处理Batch

灵活指定SQL语句中的变量

-PreparedStatement

对存储过程进行调用

-CallableStatement

运用事务处理

-Transaction

批处理

-Batch

-对于大量的批处理,建议使用statement,因为PreparedStatement的预编译空间有限,当数据量特别大的时候,会发生异常

-事务提交方式设为手动提交

conn.setAutoCommit(false);//设为手动提交
            
            stmt=conn.createStatement();
            long start =System.currentTimeMillis();
            for(int i=0;i<20000;i++) {
                stmt.addBatch("insert into t_user (username,pwd,regTime) values ('zhang"+i+"',1234,now())"); 
            }
            stmt.executeBatch();
            conn.commit();
            long end =System.currentTimeMillis();
            System.out.println("耗时:"+(end-start)+"ms");
/**
*Output:耗时:14422ms
**/

 

posted @ 2019-08-26 17:34  小帆敲代码  阅读(106)  评论(0编辑  收藏  举报