当前位置:网站首页>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
边栏推荐
- PV静态创建和动态创建
- XML配置文件(DTD详细讲解)
- Redis高可用——主从复制、哨兵模式、集群
- Qt 一个简单的word文档编辑器
- Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
- 教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!
- 5. Logistic regression
- Initialize your vector & initializer with a list_ List introduction
- Make a short video clip number of we media film and television. Where can I download the material?
- 什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
猜你喜欢

【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)

After summarizing more than 800 kubectl aliases, I'm no longer afraid that I can't remember commands!

认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)

Spire. PDF for NET 8.7.2

My colleagues quietly told me that flying Book notification can still play like this

Huawei equipment is configured with OSPF and BFD linkage
![[online chat] the original wechat applet can also reply to Facebook homepage messages!](/img/d2/1fd4de4bfd433ed397c236ddb97a66.png)
[online chat] the original wechat applet can also reply to Facebook homepage messages!

C reflection and type

Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste

XML配置文件(DTD详细讲解)
随机推荐
Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
Effet Doppler (déplacement de fréquence Doppler)
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
云呐|固定资产管理系统主要操作流程有哪些
My colleagues quietly told me that flying Book notification can still play like this
Shardingsphere source code analysis
openssl-1.0.2k版本升级openssl-1.1.1p
7.5模拟赛总结
行列式学习笔记(一)
关于结构体所占内存大小知识
Use CAS instead of synchronized
GFS Distributed File System
In C#, why can't I modify the member of a value type instance in a foreach loop?
After summarizing more than 800 kubectl aliases, I'm no longer afraid that I can't remember commands!
Fiddler Everywhere 3.2.1 Crack
PV静态创建和动态创建
多普勒效應(多普勒頻移)
如何获取localStorage中存储的所有值
如何让同步/刷新的图标(el-icon-refresh)旋转起来
rsync远程同步