首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

struts2下传excel文件并解析数据插入数据库

2012-08-30 
struts2上传excel文件并解析数据插入数据库@SuppressWarnings(unchecked)public String uploadAlarmRmsJ

struts2上传excel文件并解析数据插入数据库

@SuppressWarnings("unchecked")public String uploadAlarmRmsJkmalfuncexperience(){String date = new SimpleDateFormat("yyyyMMddHHmmssSS").format(new Date()); ServletContext aplication = ServletActionContext.getServletContext();String path = aplication.getRealPath("/excel");System.out.println(path);FileUtil.copyFileToDir(path, upload, date+"_"+uploadFileName);try {InputStream is = new FileInputStream(new File(path,date+"_"+uploadFileName));try {Workbook book= Workbook.getWorkbook(is);Sheet seet= book.getSheet(0);List<AlarmRmsJkmalfuncexperience> lists = new ArrayList();AlarmRmsJkmalfuncexperience jkmalfuncexperience=null;for(int i=1;i<seet.getRows();i++){jkmalfuncexperience =new AlarmRmsJkmalfuncexperience();jkmalfuncexperience.setExpid(seet.getCell(0,i).getContents());jkmalfuncexperience.setExptitle(seet.getCell(1,i).getContents());jkmalfuncexperience.setMalfuncarea(seet.getCell(2,i).getContents());jkmalfuncexperience.setSpecialtype(seet.getCell(3,i).getContents());jkmalfuncexperience.setDevicetype(seet.getCell(4,i).getContents());jkmalfuncexperience.setDevicecompany(seet.getCell(5,i).getContents());jkmalfuncexperience.setVersion(seet.getCell(6,i).getContents());jkmalfuncexperience.setExplevel(seet.getCell(7,i).getContents());jkmalfuncexperience.setExpkeyword(seet.getCell(8,i).getContents());jkmalfuncexperience.setMalfuncdescription(seet.getCell(9,i).getContents());jkmalfuncexperience.setExperiencesummary(seet.getCell(10,i).getContents());lists.add(jkmalfuncexperience);}alarmRmsJkmalfuncexperienceManager.saveOrUpdateAll(lists);} catch (BiffException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}return SUCCESS;}
?

热点排行