当前位置:网站首页>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
边栏推荐
- QT--线程
- Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
- Chapter 16 oauth2authorizationrequestredirectwebfilter source code analysis
- QT -- thread
- Online yaml to CSV tool
- Cloudcompare & PCL point cloud randomly adds noise
- 【EF Core】EF Core与C# 数据类型映射关系
- XML configuration file (DTD detailed explanation)
- Mathematical model Lotka Volterra
- 总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
猜你喜欢
4点告诉你实时聊天与聊天机器人组合的优势
Bao Yan notes II software engineering and calculation volume II (Chapter 13-16)
亲测可用fiddler手机抓包配置代理后没有网络
Spire. PDF for NET 8.7.2
Fiddler Everywhere 3.2.1 Crack
20. Migrate freetype font library
Online yaml to CSV tool
关于结构体所占内存大小知识
Yunna | what are the main operating processes of the fixed assets management system
STM32__ 06 - single channel ADC
随机推荐
教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!
[Luogu p3295] mengmengda (parallel search) (double)
Research notes I software engineering and calculation volume II (Chapter 1-7)
Detailed explanation of APP functions of door-to-door appointment service
跟着CTF-wiki学pwn——ret2libc1
wx.getLocation(Object object)申请方法,最新版
Configuring OSPF load sharing for Huawei devices
GFS分布式文件系統
微信小程序---WXML 模板语法(附带笔记文档)
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
Rasa 3. X learning series -rasa 3.2.1 new release
mysql-全局锁和表锁
Zhuan: in the future, such an organization can withstand the risks
Breadth first search open turntable lock
第16章 OAuth2AuthorizationRequestRedirectWebFilter源码解析
STM32__ 06 - single channel ADC
How to rotate the synchronized / refreshed icon (EL icon refresh)
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
妙才周刊 - 8
20. Migrate freetype font library