JAVA使用HikariCP开启执行批量执行插入数据
星期五, 2021-04-30 | Author: Lee | JAVA-and-J2EE | 1,122 views
1.使用HikariConfig配置如下: 开启批量处理
#mysql config jdbcUrl=jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai username=root password=root driverClassName=com.mysql.cj.jdbc.Driver dataSource.cachePrepStmts=true dataSource.prepStmtCacheSize=250 dataSource.prepStmtCacheSqlLimit=2048 dataSource.useServerPrepStmts=true dataSource.useLocalSessionState=true dataSource.rewriteBatchedStatements=true dataSource.cacheResultSetMetadata=true dataSource.statementsPerBatch=5000 #dataSource.cacheServerConfiguration=true #dataSource.elideSetAutoCommits=true dataSource.maintainTimeStats=false dataSource.useCursorFetch=true autoCommit=true maximumPoolSize=10 |
2.使用批量执行语句
String sql ="INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?)"; //ok batch sql ="INSERT INTO MyTable(ColA, ColB, ColC) VALUE (?, ?, ?)"; //no batch only Inserting one record at a time queryRunner.batch(, new Object[][] { {"A1", "B1", "C1"}, {"A2", "B2", "C2"}, {"A3", "B3", "C3"}}); |
小结:因为使用了 VALUE 不是 VALUES而无法批量生效,一直跟踪debug才发现,浪费了半天时间囧.
文章作者: Lee
本文地址: https://www.pomelolee.com/2148.html
除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址
No comments yet.
Leave a comment
Search
相关文章
热门文章
最新文章
文章分类
- ajax (10)
- algorithm-learn (3)
- Android (6)
- as (3)
- computer (85)
- Database (30)
- disucz (4)
- enterprise (1)
- erlang (2)
- flash (5)
- golang (3)
- html5 (18)
- ios (4)
- JAVA-and-J2EE (186)
- linux (143)
- mac (10)
- movie-music (11)
- pagemaker (36)
- php (50)
- spring-boot (2)
- Synology群晖 (2)
- Uncategorized (6)
- unity (1)
- webgame (15)
- wordpress (33)
- work-other (2)
- 低代码 (1)
- 体味生活 (40)
- 前端 (21)
- 大数据 (8)
- 游戏开发 (9)
- 爱上海 (19)
- 读书 (4)
- 软件 (3)