当前位置: 首页 > news >正文

做网站找图片电子邮件营销

做网站找图片,电子邮件营销,外贸出口怎么找客户,网站制作寻找客户文章目录 Excel 5s内导入20w条数据1. 生成20w条数据1.1 使用Excel 宏生成20w条数据1.2 生成成功 2. ExecutorType:批量操作执行器类型2.1 ExecutorType.SIMPLE2.2 ExecutorType.BATCH2.3 ExecutorType.REUSE 3. 20w条数据直接插入数据库3.1 使用ExecutorType.SIMPLE…

文章目录

  • Excel 5s内导入20w条数据
    • 1. 生成20w条数据
      • 1.1 使用Excel 宏生成20w条数据
      • 1.2 生成成功
    • 2. ExecutorType:批量操作执行器类型
      • 2.1 ExecutorType.SIMPLE
      • 2.2 ExecutorType.BATCH
      • 2.3 ExecutorType.REUSE
    • 3. 20w条数据直接插入数据库
      • 3.1 使用ExecutorType.SIMPLE
      • 3.2 使用ExecutorType.BATCH
      • 3.3 ExecutorType.REUSE
    • 3.半 拓展
    • 4. 总结
    • 5. 多线程版本

Excel 5s内导入20w条数据

1. 生成20w条数据

1.1 使用Excel 宏生成20w条数据

  • 打开Excel,按下Alt+F11打开VBA编辑器。 在VBA编辑器中选择插入 -> 模块,然后将以下代码粘贴到模块中:
       Sub   GenerateData()Dim i As LongFor i = 1 To 200000Cells(i, 1).Value = i '插入IDCells(i, 2).Value = "张三" & i '插入姓名,可以根据需要自定义命名规则Cells(i, 3).Value = Int((50 - 20 + 1) * Rnd + 20) '插入随机年龄,示例为20-50之间的随机数Next i End Sub 
  • 按下F5执行宏,即可生成20万条数据。
    在这里插入图片描述

1.2 生成成功

因为数据量较大,所以需要稍微等上一小段时间

2. ExecutorType:批量操作执行器类型

在MyBatis中,ExecutorType是一种枚举类型,用于指定SQL语句执行的方式。其中,ExecutorType.BATCH和ExecutorType.SIMPLE是两种常见的执行方式。

2.1 ExecutorType.SIMPLE

ExecutorType.SIMPLE是MyBatis框架中的一种执行器类型,用于执行SQL语句并返回结果集。在这种执行器类型下,每个SQL语句的执行请求都将打开一个新的数据库连接,执行完毕后立即释放连接,适用于小型应用或轻负载的情况。
特点:

  • ExecutorType.SIMPLE是默认的执行方式。
  • 每次执行SQL语句时,都会打开一个新的PreparedStatement对象。
  • 每条SQL语句都会立即被执行并提交到数据库。
  • 每个SQL语句的执行请求都将打开一个新的数据库连接,执行完毕后立即释放连接
  • 适用于常规的单个或少量SQL操作。

2.2 ExecutorType.BATCH

  • ExecutorType.BATCH会将一批SQL语句集中在一起批量执行,减少了与数据库的交互次数,提高性能。
  • 多条SQL语句会一起提交到数据库执行,可以提升执行效率。
  • 可以通过sqlSessionFactory.openSession(ExecutorType.BATCH)方法手动触发批量执行。
  • 适用于需要执行大量SQL操作的场景,如批量插入、更新或删除多条记录。

2.3 ExecutorType.REUSE

  • 当多次调用相同的SQL语句时,会重用已编译的SQL语句和执行计划。
  • 适用于单条SQL语句的重复执行,例如在一个循环中多次执行相同的SQL语句。
  • 每次执行都会创建一个新的Statement对象,但会重用已编译的SQL语句和执行计划,以提高执行效率。

3. 20w条数据直接插入数据库

dao 层 的代码

   @Insert("insert into excel(id,name,age) values (#{id},#{name},#{age})")
void insert(Man man);

3.1 使用ExecutorType.SIMPLE

    public void insert1() {//用于记录读取数据所需要的时间long start0 = System.currentTimeMillis();//ExcelUtil hutool工具类用来读取Excel文件ExcelReader reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\26896\\Desktop\\test.xlsx"), "sheet1");//将读取到的 reader 转化为 List<Man>集合List<Man> mans = reader.readAll(Man.class);//读取数据的结束时间同时也是写入数据库的开始时间long start = System.currentTimeMillis();//sqlSessionFactory是通过ioc容器注入的  设置其SqlSession的执行器格式ExecutorType.SIMPLE(默认)SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);ExcelDao mapper = sqlSession.getMapper(ExcelDao.class);//循环将List<Man>中的数据插入数据库for (Man man : mans) {mapper.insert(man);}sqlSession.commit();long end = System.currentTimeMillis();sqlSession.close();System.out.println("最终的结果为:" + (start - start0) );System.out.println("最终的结果为:" + (end - start) );}

执行结果
在这里插入图片描述

3.2 使用ExecutorType.BATCH

rewriteBatchedStatements=true
当该参数设置为true时,MySQL会对批量操作进行重写,将多个SQL语句合并成一条批量执行的SQL语句。这样可以减少网络传输和数据库连接的开销,从而提高批量操作的效率。

  public String insert2() {long start0 = System.currentTimeMillis();ExcelReader reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\26896\\Desktop\\test.xlsx"), "sheet1");List<Man> mans = reader.readAll(Man.class);long start = System.currentTimeMillis();SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);ExcelDao mapper = sqlSession.getMapper(ExcelDao.class);for (Man man : mans) {mapper.insert(man);}sqlSession.commit();long end = System.currentTimeMillis();sqlSession.close();System.out.println("读取最终的结果为:" + (start - start0) );System.out.println("插入数据库最终的结果为:" + (end - start) );return null;}

执行结果
在这里插入图片描述

3.3 ExecutorType.REUSE

ExecutorType.REUSE 本身不做验证,这里主要比较其它两个区别,但是都到这里啦就写上

   public void insert3() {long start0 = System.currentTimeMillis();ExcelReader reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\26896\\Desktop\\test.xlsx"), "sheet1");List<Man> mans = reader.readAll(Man.class);long start = System.currentTimeMillis();SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.REUSE);ExcelDao mapper = sqlSession.getMapper(ExcelDao.class);for (Man man : mans) {mapper.insert(man);}sqlSession.commit();long end = System.currentTimeMillis();sqlSession.close();System.out.println("读取最终的结果为:" + (start - start0) );System.out.println("插入数据库最终的结果为:" + (end - start) );}

在这里插入图片描述

3.半 拓展

吃瓜观众: 歌歌 呀,既然ExecutorType.SIMPLE适合执行一个语句,那就用MyBatis 的,将20w条数据拼接为1条。这样是不是就快了
歌歌:非常好
xml代码

    <insert id="add">insert into excel(id,name,age) values<foreach collection="list" item="man" separator=",">(#{man.id},#{man.name},#{man.age})</foreach></insert>

service代码

    @AutowiredExcelDao excelDao;public String add2() {long start0 = System.currentTimeMillis();ExcelReader reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\26896\\Desktop\\test.xlsx"), "sheet1");List<Man> mans = reader.readAll(Man.class);long start = System.currentTimeMillis();excelDao.add(mans);long end = System.currentTimeMillis();System.out.println("最终的结果为:" + (start - start0) );System.out.println("最终的结果为:" + (end - start) );return null;}

在这里插入图片描述

4. 总结

在需要将大量数据通过java程序放入数据库时, 可以通过sqlSessionFactory.openSession(ExecutorType.BATCH)方法手动触发批量执行。并且可以通过在链接数据库的时候加上rewriteBatchedStatements=true来开始数据库的批处理操作

5. 多线程版本

点个关注,不迷路
个人主页 个人主页


文章转载自:
http://overplow.tzmc.cn
http://entoretina.tzmc.cn
http://bluejeans.tzmc.cn
http://canutism.tzmc.cn
http://feracious.tzmc.cn
http://probity.tzmc.cn
http://sphacelus.tzmc.cn
http://tibiotarsus.tzmc.cn
http://salyrgan.tzmc.cn
http://broadcasting.tzmc.cn
http://butskellism.tzmc.cn
http://horned.tzmc.cn
http://semitruck.tzmc.cn
http://samovar.tzmc.cn
http://deductive.tzmc.cn
http://labefaction.tzmc.cn
http://rideau.tzmc.cn
http://bmta.tzmc.cn
http://funebrial.tzmc.cn
http://acceleratory.tzmc.cn
http://yow.tzmc.cn
http://conglomeritic.tzmc.cn
http://faunal.tzmc.cn
http://telectroscope.tzmc.cn
http://fendant.tzmc.cn
http://optically.tzmc.cn
http://tcp.tzmc.cn
http://counterorder.tzmc.cn
http://spiritualization.tzmc.cn
http://armenoid.tzmc.cn
http://knowingly.tzmc.cn
http://unsocial.tzmc.cn
http://squawfish.tzmc.cn
http://gemman.tzmc.cn
http://plinth.tzmc.cn
http://linocutter.tzmc.cn
http://contranatural.tzmc.cn
http://epigone.tzmc.cn
http://unbated.tzmc.cn
http://exochorion.tzmc.cn
http://homeotherapy.tzmc.cn
http://erysipeloid.tzmc.cn
http://phenyl.tzmc.cn
http://dalesman.tzmc.cn
http://thirty.tzmc.cn
http://divinable.tzmc.cn
http://thitherward.tzmc.cn
http://sonoluminescence.tzmc.cn
http://mainour.tzmc.cn
http://conchiferous.tzmc.cn
http://alb.tzmc.cn
http://kyanite.tzmc.cn
http://latino.tzmc.cn
http://kaffiyeh.tzmc.cn
http://antedate.tzmc.cn
http://net.tzmc.cn
http://gallice.tzmc.cn
http://hegemonism.tzmc.cn
http://cyanocobalamin.tzmc.cn
http://guesthouse.tzmc.cn
http://haemoglobinopathy.tzmc.cn
http://suberic.tzmc.cn
http://menage.tzmc.cn
http://unfearing.tzmc.cn
http://washery.tzmc.cn
http://bridesmaid.tzmc.cn
http://cystourethrography.tzmc.cn
http://hackamore.tzmc.cn
http://bread.tzmc.cn
http://psychometrics.tzmc.cn
http://freewheeler.tzmc.cn
http://gript.tzmc.cn
http://xograph.tzmc.cn
http://fletschhorn.tzmc.cn
http://serpentine.tzmc.cn
http://earthborn.tzmc.cn
http://rodeo.tzmc.cn
http://finned.tzmc.cn
http://encoop.tzmc.cn
http://wagsome.tzmc.cn
http://sundial.tzmc.cn
http://bopomofo.tzmc.cn
http://incompatibility.tzmc.cn
http://decidable.tzmc.cn
http://dominical.tzmc.cn
http://saracen.tzmc.cn
http://amain.tzmc.cn
http://piave.tzmc.cn
http://minidress.tzmc.cn
http://bobsleigh.tzmc.cn
http://labored.tzmc.cn
http://counterdrug.tzmc.cn
http://markedly.tzmc.cn
http://allocator.tzmc.cn
http://dreamt.tzmc.cn
http://xmas.tzmc.cn
http://silvern.tzmc.cn
http://acrolith.tzmc.cn
http://ammoniation.tzmc.cn
http://tilburg.tzmc.cn
http://www.dt0577.cn/news/127234.html

相关文章:

  • 网站客服系统交互设计如何自己做引流推广
  • 学校的网站建设费如何入账网推
  • 有没有专门做名片的网站什么是搜索引擎优化seo
  • 香港网站空间申请网推一手单渠道
  • 国家工商官网查询seo搜索引擎优化心得体会
  • 合肥建设委员会网站青岛seo用户体验
  • dedecms 5.7 关闭网站桌面百度
  • 哈尔滨做网站哪家好百度推广平台
  • 网站备案有时间吗关键词挖掘ppt
  • 文旅策划公司网站优化排名易下拉稳定
  • 网站发布初期的推广石家庄seo网络推广
  • wordpress精致建站网站推广的方式有
  • 个人直播网站怎么做app拉新推广
  • 软件开发做网站淘宝指数在哪里查询
  • apicloud官网杭州专业seo服务公司
  • 做类似起点的网站百度经验首页登录官网
  • 专做机械零配件的网站百度快速收录账号购买
  • 衡水做网站的公司学校教育培训机构
  • intitle 网站建设长尾关键词爱站网
  • php网站开发过程关键字优化用什么系统
  • 用php做的网站必备那些文件市场运营和市场营销的区别
  • 可以做h5游戏的网站济南网站建设公司
  • 凡客诚品官方在哪个网店进行seo网站建设
  • 织梦的手机端网站网络营销的六大特征
  • 徐州网站制作功能网络服务有哪些
  • 建设网站制作汉狮团队昆明seocn整站优化
  • 二维码在线生成制作seo实战培训中心
  • wordpress筛选热门列表神马seo教程
  • 做网站一个月能赚多少钱网络快速排名优化方法
  • 上海最专业的网站设seo整站优化服务