2 yjwzsrzj YJWZSRZJ 于 2017.09.16 16:07 提问

ssh poi 导入导出,报could not execute statement 5C
@Action(value = "undoexcel",results={@Result(name="success",location="/WEB-INF/jsp/function/billqq.jsp")})
    public String undo() throws Exception{
        String directory = "/file";
        String targetDirectory = ServletActionContext.getServletContext().getRealPath(directory);
        File target = UploadFile.Upload(upload, uploadFileName, targetDirectory);
        List<BillEntity> billList = new ArrayList<BillEntity>();
        excelFile = new FileInputStream(target);
        Workbook workbook = new HSSFWorkbook(excelFile);
        Sheet sheet = workbook.getSheetAt(0);
        int rowNum = sheet.getLastRowNum() + 1;
        for (int i = 1; i < rowNum; i++) {
            BillEntity billentity = new BillEntity();
            Row row = sheet.getRow(i);
            int cellNum = row.getLastCellNum();
            for (int j = 0; j < cellNum; j++) {
                Cell cell = row.getCell(j);
                String cellValue = null;
                switch (cell.getCellType()) { // 判断excel单元格内容的格式,并对其进行转换,以便插入数据库
                case 0:
                    cellValue = String
                            .valueOf((int) cell.getNumericCellValue());
                    break;
                case 1:
                    cellValue = cell.getStringCellValue();
                    break;
                case 2:
                    cellValue = String
                            .valueOf((int) cell.getNumericCellValue());
                    break;
                case 3:
                    cellValue = cell.getStringCellValue();
                    break;
                case 4:
                    cellValue = cell.getStringCellValue();
                    break;
                }

                switch (j) {// 通过列数来判断对应插如的字段
                case 1:
                    billentity.setBi_date(cellValue);
                    break;
                case 2:

                    billentity.setIncome(Integer.valueOf(cellValue));
                    break;
                case 3:
                    billentity.setExpend(Integer.valueOf(cellValue));
                    break;
                case 4:
                    billentity.setRemark(cellValue);
                    break;  
                }

            }
            billList.add(billentity);
        }
        baseService.add(billList);

        return "success";
    }

 @Override
        public void add(List<BillEntity> billentity) {
            // TODO Auto-generated method stub
            Session session=sessionfactory.openSession();
            if(billentity.size() > 0){
                int sNum = billentity.size();
                for(int i=0;i<sNum;i++){
                    session.saveOrUpdate(billentity.get(i));
                }
                session.beginTransaction().commit();


            }

3个回答

devmiao
devmiao   Ds   Rxr 2017.09.16 23:55
privateobject
privateobject   2017.09.18 16:28

报错的输出呢?没有看到,怎么判断

YJWZSRZJ
YJWZSRZJ   2017.09.17 10:43

自己顶一下,非常急

Csdn user default icon
上传中...
上传图片
插入图片