java中解析excel 批量插入数据库
Facade 层 实现类 (@Service("samePeriodModelImportFacade"))
1、 获取cells 的方法
public Cells getCells(File file){
Cells cells = null;
License license = new License();
InputStream licenseStream = this.getClass().getResourceAsStream("/aspose.lic");
try{
license.setLicense(licenseStream);
FileInputStream fr = new FileInputStream(file);
Workbook wb = new Workbook(fr);
Worksheet worksheet = wb.getWorksheets().get(0);
cells = worksheet.getCells();
}catch(Exception e){
e.printStackTrace();
}
return cells;
}
2、解析excel 的方法
public String analyExcel(File file){
String dis_no=null;
String dis_mp=null;
List<Object[ ]> insertParamList =new ArrayList<Object[ ]>();
Cells cells = this.getCells( file);
for(int i=1;i<cells.getMaxDataRow()+1;i++){ // 获取要数据的最大的行数
for(int j=0; j<35;j++){ //获取列数 例如35列
String cellsValue = cells.getRows().get(i).get(j).getStringValue(); // 获取的每一个单元格的数据 返回的是String 类型
if(j==0){
dis_no =cellsValue; // i=1 j=0
}
if( j==23){
dis_mp=cellsValue; // i =1 j=23
}
}
insertParamList.add(new Object[] {dis_no,dis_mp});
}
samePeriodModelImportDomainService.insertPspCellModel(insertParamList);
return "success";
}
service层实现类@Repository("samePeriodModelImportDomainService")
//批量插入数据库
public void insertPspCellModel(List<Object[]> insertParamList) {
String sql = "insert into psp_model(dis_no,dis_mp) values(?,?)";
this.getJdbcTemplate().batchUpdate(sql, insertCellParamList);
}
aspose.lic
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>
java中解析excel 批量插入数据库的更多相关文章
- 多线程查询数据,将结果存入到redis中,最后批量从redis中取数据批量插入数据库中【我】
多线程查询数据,将结果存入到redis中,最后批量从redis中取数据批量插入数据库中 package com.xxx.xx.reve.service; import java.util.ArrayL ...
- SqlBulkCopy将DataTable中的数据批量插入数据库中
#region 使用SqlBulkCopy将DataTable中的数据批量插入数据库中 /// <summary> /// 注意:DataTable中的列需要与数据库表中的列完全一致.// ...
- list转datatable,SqlBulkCopy将DataTable中的数据批量插入数据库
/// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...
- PHP如何将多维数组中的数据批量插入数据库?
PHP将多维数组中的数据批量插入到数据库中,顾名思义,需要用循环来插入. 1.循环insert into 语句,逐渐查询 <?php /* www.qSyz.net */ @mysql_conn ...
- Java实现http大文件流读取并批量插入数据库
1.概述 请求远程大文本,使用流的方式进行返回.需要设置http链接的超时时间 循环插入到List中,使用mybatis-plus批量插入到mysql中 2.需求 两台服务器 大文件放到其中一台服务器 ...
- Java MySql 批量插入数据库addBatch
//addBatch批量插入数据库 public static void insertCommentToMySql(Set<String> commentList) { Iterator& ...
- 【MySql】Java 批量插入数据库addBatch
//addBatch批量插入数据库 public static void insertCommentToMySql(Set<String> commentList) { Iterator& ...
- 将Excle中的数据批量导入数据库
namespace 将Excle中的数据批量导入数据库{ class Program { static void Main(string[] args) { S ...
- sql server 使用SqlBulkCopy批量插入数据库
sql server sqlbulkcopy 批量数据插入数据库使用的是System.Data.SqlClient中的 SqlBulkCopy批量数据插入数据库 sql server 使用SqlBul ...
随机推荐
- LINUX FTPshez
https://www.jb51.net/article/132337.htm FTPQ重启: service vsftpd restart
- OPNET下op_pk_copy()函数使用注意事项
1)op_pk_copy()是生成新的数据包,函数op_pk_create_time_get()获取的是新数据包的生成时间.在统计数据包的端到端时延,以及服务时延需要注意. 2)此外发用数据包时使用o ...
- 数据库中id为自增
使用find_and_modify函数可以设置mongo的id为自增 且可以支持原有的高并发操作,find_and_modify函数完成更新查找两个操作其是原子性的操作 代码:(auto_id.py) ...
- mongodb mac
==> mongodb To have launchd start mongodb now and restart at login: brew services start mongodb O ...
- Linux进阶指令(重点)
三.Linux进阶指令(重点) 1.df指令 作用:查看磁盘的空间 #df -h 选项:-h 表示以可读性较高的形式展示大小 2.free指令 作用:查看内存使用情况 #free ...
- 来源于知乎专栏:https://zhuanlan.zhihu.com/p/29619457
1. 校验数字的表达式 1 数字:^[0-9]*$ 2 n位的数字:^\d{n}$ 3 至少n位的数字:^\d{n,}$ 4 m-n位的数字:^\d{m,n}$ 5 零和非零开头的数字:^(0|[1- ...
- ExcelPackage 读取、导出excel
private static string GetString(object obj) { try { return obj.ToString(); } catch (Exception ex) { ...
- 5. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
解决方案,见 https://www.jianshu.com/p/836d455663da
- java面试题复习(四)
31.内部类可以引用它的外部类的私有成员吗? 可以,内部类对象可以访问创建它的外部类对象的成员 32.final关键字有哪些用法? 修饰类时该类不能被继承,修饰方法时,该方法不能被重写,修饰变量时表示 ...
- anaconda安装Opencv报错:Could NOT find PythonLibs: Found unsuitable version "2.7.6",
机器上装了两个python,一个是默认的,一个是anaconda.安装opencv时就报错了: -- Found PythonInterp: /home/deeplp/anaconda2/bin/py ...