java]
view plain
copy
public String cmdImpQxsj() { String sysGuid = getWorkDTO().getAsString(
"sysGuid"); String webPath = WebConfig.getInstance().getContext_path(); String filePath =
this.getFilePath(sysGuid); String longPath = webPath+filePath; HSSFWorkbook workbook = POIExcelUtil.getExistHSSFWorkbook(
new File(longPath)); List<List<Object>> list =
new ArrayList<List<Object>>(); if (workbook != null) { HSSFSheet sheet = workbook.getSheetAt(
0); if (sheet != null) { int rownum = sheet.getLastRowNum(); int columnnum = sheet.getRow(0).getLastCellNum(); for(int i=3;i<rownum;i++){ List<Object> row =
new ArrayList<Object>(); Object value =
""; for (int j = 1; j < columnnum-1; j++) { Cell cell = sheet.getRow(i).getCell(j);
if (cell == null) { row.add(
""); }
else if (j==2 || j==3 || j == 5 || j==
6 || j==7 || j == 9 || j==10 || j==
11 || j == 12 || j==13 || j == 15 || j==
16 || j==18 || j == 19 || j==20) { if(cell.getStringCellValue() != null || !"".equals(cell.getStringCellValue())){ value = cell.getStringCellValue(); row.add(value); } }
else if(j == 1){ if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){ int d = (int)cell.getNumericCellValue(); String numb = d+
""; row.add(numb); }
else if(cell.getStringCellValue() != null || !"".equals(cell.getStringCellValue())){ value = cell.getStringCellValue(); row.add(value); } }
else if (j == 4 || j == 14 || j == 17){ if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { value = cell.getDateCellValue(); }
else { value = cell.getStringCellValue(); }
if (value == null || "".equals(value.toString())) { row.add(
""); }
else { SimpleDateFormat sdf =
new SimpleDateFormat( "yyyy-MM-dd HH:mm"); if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { try { value = sdf.format(value); }
catch (Exception e) { value =
""; } } row.add(value); } }
else if (j == 8){ if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { value = cell.getDateCellValue(); }
else { value = cell.getStringCellValue(); }
if (value == null || "".equals(value.toString())) { row.add(
""); }
else { SimpleDateFormat sdf =
new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { try { value = sdf.format(value); }
catch (Exception e) { value =
""; } } row.add(value); } } } list.add(row); }
try { impToDB(list); getWorkDTO().put(
"jsonString", "{success:true}"); }
catch (SQLException e) { getWorkDTO().put(
"jsonString", "{failure:true}"); e.printStackTrace();
return ICnsExResult.RUSULT_ERROR; } } }
return ICnsExResult.RUSULT_SUCCESS; }
@SuppressWarnings("static-access") public void impToDB(List<?> list) throws SQLException{ String sql =
""; SimpleDateFormat format =
new SimpleDateFormat("yyyy-MM-dd KK:mm:ss"); String cretDate = format.format(
new Date());String jobID = getSessionDTO().getAsString(SessionDTO.LOGIN_USR_JOBID); sql =
"insert into us_app.tb_ope_qxsc(guid,qxgd,qxmc,gddqzt," + "dqztxgsj,clqk,gdsqr,sqrzb,fxsj,zy,jzmc,qxlb,sbmc,jxr," + "jxyssj,wxr,xqr,xqsj,tjpzr,bz,gzpbh,scsj,scgh) " + "values(sys_guid(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; Connection con =
this.baseDAO.toGetSession().connection(); PreparedStatement ps = con.prepareStatement(sql);
final int batchSize = 60; int count = 0; for(int p=0;p<list.size();p++){ List<?> singleList = (List<?>)list.get(p); ps.setString(
1, (String) singleList.get(0)); ps.setString(
2, (String) singleList.get(1)); ps.setString(
3, (String) singleList.get(2)); if("".equals(singleList.get(3))){ ps.setTimestamp(
4, null); }
else{ ps.setTimestamp(
4, returnDate((String) singleList.get(3))); } ps.setString(
5, (String) singleList.get(4)); ps.setString(
6, (String) singleList.get(5)); ps.setString(
7, (String) singleList.get(6)); if("".equals(singleList.get(7))){ ps.setTimestamp(
8, null); }
else{ ps.setTimestamp(
8, returnDate2((String) singleList.get(7))); } ps.setString(
9, (String) singleList.get(8)); ps.setString(
10, (String) singleList.get(9)); ps.setString(
11, (String) singleList.get(10)); ps.setString(
12, (String) singleList.get(11)); ps.setString(
13, (String) singleList.get(12)); if("".equals(singleList.get(13))){ ps.setTimestamp(
14, null); }
else{ ps.setTimestamp(
14, returnDate((String) singleList.get(13))); } ps.setString(
15, (String) singleList.get(14)); ps.setString(
16, (String) singleList.get(15)); if("".equals(singleList.get(16))){ ps.setTimestamp(
17, null); }
else{ ps.setTimestamp(
17, returnDate((String) singleList.get(16))); } ps.setString(
18, (String) singleList.get(17)); ps.setString(
19, (String) singleList.get(18)); ps.setString(
20, (String) singleList.get(19)); ps.setTimestamp(
21, new java.sql.Timestamp(new java.util.Date().getTime())); ps.setString(
22, jobID); ps.addBatch();
if(++count % batchSize == 0) { ps.executeBatch(); ps.clearBatch(); } } ps.executeBatch(); ps.clearBatch(); }
public Timestamp returnDate(String date){ Timestamp dateTime =
null; try{ DateFormat dateFormat; dateFormat =
new SimpleDateFormat("yyyy-MM-dd kk:mm",Locale.ENGLISH);dateFormat.setLenient(
false); java.util.Date timeDate = dateFormat.parse(date);dateTime =
new java.sql.Timestamp(timeDate.getTime());}
catch(Exception ex){ ex.printStackTrace(); }
return dateTime; }
public Timestamp returnDate2(String date){ Timestamp dateTime =
null; try{ DateFormat dateFormat; dateFormat =
new SimpleDateFormat("yyyy-MM-dd kk:mm:ss",Locale.ENGLISH);dateFormat.setLenient(
false); java.util.Date timeDate = dateFormat.parse(date);dateTime =
new java.sql.Timestamp(timeDate.getTime());}
catch(Exception ex){ ex.printStackTrace(); }
return dateTime; }
转(http://blog.csdn.net/haima573979352/article/details/13505339)
转载于:https://www.cnblogs.com/sunshine-in/p/4095504.html
相关资源:JAVA实现Excel表数据导入ORACLE数据库