JDBC05 其他操作及批处理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
**/
扫描二维码关注公众号,回复: 7102141 查看本文章

猜你喜欢

转载自www.cnblogs.com/code-fun/p/11413852.html