当前位置:网站首页>提升工作效率工具:SQL批量生成工具思想
提升工作效率工具:SQL批量生成工具思想
2022-07-05 23:51:00 【haohaounique】
提升工作效率:将excel文件数据转为sql,批量生成sql执行脚本
1.适用于此类读取excel数据并加工成sql文件的场景【简单场景易推荐使用工具本身快捷键如idea notepad,vscode sublime工具自带列选】
easyexcel参考:读Excel | Easy Excel
2.maven 引用
<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>话不多说看代码
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 = "用户名")
private String name;
@ExcelProperty(value = "年龄")
private int age;
@ExcelProperty(value = "地址")
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("'", "''");
}
}
效果

注意:需要将部分特殊的符号替换,具体看使用的场景
边栏推荐
- Spire Office 7.5.4 for NET
- Convert Chinese into pinyin
- The PostgreSQL column reference 'ID' is ambiguous - PostgreSQL column reference'id'is ambiguous
- 【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
- Senparc. Weixin. Sample. MP source code analysis
- Use CAS instead of synchronized
- After summarizing more than 800 kubectl aliases, I'm no longer afraid that I can't remember commands!
- Research notes I software engineering and calculation volume II (Chapter 1-7)
- 5. Logistic regression
- 20220703 周赛:知道秘密的人数-动规(题解)
猜你喜欢

Upgrade openssl-1.1.1p for openssl-1.0.2k

Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration

Fiddler Everywhere 3.2.1 Crack

GFS distributed file system

Spreadjs 15.1 CN and spreadjs 15.1 en

Qt QPushButton详解

Redis高可用——主从复制、哨兵模式、集群

Senparc. Weixin. Sample. MP source code analysis

GFS分布式文件系统

微信小程序---WXML 模板语法(附带笔记文档)
随机推荐
Zhuan: in the future, such an organization can withstand the risks
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
4 points tell you the advantages of the combination of real-time chat and chat robots
CAS and synchronized knowledge
关于结构体所占内存大小知识
上门预约服务类的App功能详解
Doppler effect (Doppler shift)
做自媒体影视短视频剪辑号,在哪儿下载素材?
云呐|公司固定资产管理系统有哪些?
如何让同步/刷新的图标(el-icon-refresh)旋转起来
CloudCompare&PCL 点云随机添加噪声
MySQL delete uniqueness constraint unique
Online yaml to CSV tool
Qt 一个简单的word文档编辑器
GFS分布式文件系統
14 MySQL view
Go language introduction detailed tutorial (I): go language in the era
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
2022.7.5-----leetcode.729
Russian Foreign Ministry: Japan and South Korea's participation in the NATO summit affects security and stability in Asia