我们通常遇到批量执行导入数据,当数据量特别大的时候,通过手动拼接sql然后去数据执行是很不现实的,所以我们可以使用脚本将文件数据生成sql,最后用sql去数据库批量插入或者更新
1、 引入poi相关jar包pom文件
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.7</version>
</dependency>
2、程序解析Excel文件生成sql脚本
2.1 建立映射文件列的对象bean
@Data
public class cityExcelBean {
/**
* oracle城市Id
*/
private String oraCityId;
/**
* 货拉拉城市编码
*/
private String cityCode;
/**
* 货拉拉城市名称
*/
private String cityName;
}
2.2 解析文件
public class excelToSql {
public static void executeCityInfo() throws IOException {
String filePath = "D:/tt/citynfo.xlsx";