private boolean import_to_database(String excel_path) throws BiffException, IOException, HsException{ File file = new File(excel_path);//根据文件名创建一个文件对象 Workbook wb = Workbook.getWorkbook(file);//从文件流中取得Excel工作区对象 Sheet sheet = wb.getSheet(0);//从工作区中取得页,取得这个对象的时候既可以用名称来获得,也可以用序号。 for(int i=0; i < sheet.getRows() && sheet.getRows()>1; i++){ if( i == 0) i++; Cell[] cells = sheet.getRow(i); boolean data_check = checkData(cells, i); if(data_check){ DxjgxxDao dxjgxxDao = new DxjgxxDao(request, response); try { Dxjgxx dxjgxx = dxjgxxDao.getDxjgxxFromCells(cells); String sql = "select j.dxjgdm from jg_dxjg j where j.dxjgdm =\'"+ dxjgxx.getDxjgdm() +"\'"; List liIs = this.findSql(sql); String sqlUpt = ""; if (liIs != null && liIs.size() > 0) { sqlUpt = dxjgxxDao.GetUpdate(dxjgxx); }else{ sqlUpt = dxjgxxDao.GetInsert(dxjgxx); } this.exeSql(sqlUpt); } catch (Exception e) { e.printStackTrace(); this.info("第" + i + "条数据插入失败!" + e); } } cells = null; } } sheet = null; wb = null; file = null; return true; }
将Excel中的数据批量导入数据库表
内容版权声明:除非注明,否则皆为本站原创文章。