您当前的位置: 首页 > 

顺其自然~

暂无认证

  • 0浏览

    0关注

    1317博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

jdbc批量插入的4种方式

顺其自然~ 发布时间:2022-10-11 15:44:28 ,浏览量:0

mysql数据库准备
#打开数据库test01;
use test01;
#创建表a,表a包含int型的id列、可变长度型的name【长度20个字符】
create table a
(
    id   INT,
    NAME VARCHAR(20)
);
jar包准备 引入依赖【不知道什么是依赖的可查看Maven的配置与使用】

    
    
      mysql
      mysql-connector-java
      5.1.49
    

    
    
      junit
      junit
      4.11
      test
    
    
  
方式一:普通插入
/**
     * 方式一
     * 普通批量插入,直接将插入语句执行多次即可
     */
    @Test
    public void bulkSubmissionTest1() {
        long start = System.currentTimeMillis();//开始计时【单位:毫秒】
        Connection conn = jdbcUtils.getConnection();//获取数据库连接
        String sql = "insert into a(id, name) VALUES (?,null)";
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            for (int i = 1; i             
关注
打赏
1662339380
查看更多评论
0.0523s