当前位置:网站首页>Tools to improve work efficiency: the idea of SQL batch generation tools
Tools to improve work efficiency: the idea of SQL batch generation tools
2022-07-05 23:57:00 【haohaounique】
Improve work efficiency : take excel Convert to file sql, Batch build sql Execute the script
1. Suitable for such reading excel Data and processing into sql File scenario 【 For simple scenarios, it is easy to recommend using the shortcut keys of the tool itself, such as idea notepad,vscode sublime The tool has its own column selection 】
easyexcel Reference resources : read Excel | Easy Excel
2.maven quote
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>Don't talk about the code
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileWriter;
import java.util.List;
/**
* description:
*/
@Data
@Slf4j
public class User {
@ExcelProperty(value = " user name ")
private String name;
@ExcelProperty(value = " Age ")
private int age;
@ExcelProperty(value = " Address ")
private String address;
public static void main(String[] args) throws Exception {
List<User> list = EasyExcel.read("C:\\Users\\haoha\\Desktop\\user.xls", User.class, null).doReadAllSync();
System.out.println(list);
StringBuilder sb = new StringBuilder();
for (User user : list) {
sb.append("insert into user(user_name,age,address)value");
sb.append("(");
sb.append("'").append(replaceWord(user.getName())).append("',");
sb.append("'").append(user.getAge()).append("',");
sb.append("'").append(replaceWord(user.getAddress())).append("',");
sb.append(");");
sb.append("\r\n");
}
try (FileWriter writer = new FileWriter(new File("D:\\develop\\xk\\common-module\\src\\main\\java\\com\\bean\\user.sql"));) {
writer.write(sb.toString());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
public static String replaceWord(String word) {
if (word == null) {
return word;
}
return word.replace("'", "''");
}
}
effect

Be careful : Some special symbols need to be replaced , It depends on the use scenario
边栏推荐
- My colleagues quietly told me that flying Book notification can still play like this
- Single merchant v4.4 has the same original intention and strength!
- 微信小程序---WXML 模板语法(附带笔记文档)
- Problem solving win10 quickly open ipynb file
- [binary search tree] add, delete, modify and query function code implementation
- PV static creation and dynamic creation
- 俄外交部:日韩参加北约峰会影响亚洲安全稳定
- 跟着CTF-wiki学pwn——ret2libc1
- 云呐|固定资产管理系统主要操作流程有哪些
- Asynchronous task Whenall timeout - Async task WhenAll with timeout
猜你喜欢

What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?
![[binary search tree] add, delete, modify and query function code implementation](/img/38/810a83575c56f17a7a0ed428a2e02e.png)
[binary search tree] add, delete, modify and query function code implementation

Learn PWN from CTF wiki - ret2libc1

wx.getLocation(Object object)申请方法,最新版

Spire. PDF for NET 8.7.2

关于结构体所占内存大小知识

单商户V4.4,初心未变,实力依旧!

Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!

Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI

PADS ROUTER 使用技巧小记
随机推荐
Senparc.Weixin.Sample.MP源码剖析
How to rotate the synchronized / refreshed icon (EL icon refresh)
Asynchronous task Whenall timeout - Async task WhenAll with timeout
GFS Distributed File System
[binary search tree] add, delete, modify and query function code implementation
PV static creation and dynamic creation
PADS ROUTER 使用技巧小记
如何让同步/刷新的图标(el-icon-refresh)旋转起来
Bao Yan notes II software engineering and calculation volume II (Chapter 13-16)
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
7.5 装饰器
云呐|公司固定资产管理系统有哪些?
Huawei equipment is configured with OSPF and BFD linkage
俄外交部:日韩参加北约峰会影响亚洲安全稳定
QT a simple word document editor
el-cascader的使用以及报错解决
Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
Do you regret becoming a programmer?
What are Yunna's fixed asset management systems?
QT--线程