当前位置: 首页 > 知识库问答 >
问题:

EmptyResultDataAccessException:结果大小不正确:预期为1,实际为0

单品
2023-03-14

当我提交复制数据时,我出现了以下错误,这里是代码…

public String deleteExistingRecordWeekWise(String monthOrWeek) throws ApplicationException {

    try {

        setMonthAndArea();

        String[] stringValues = selectedMonthAndYear.split("-");
        int year=Integer.parseInt(stringValues[0]);
        int month=Integer.parseInt(stringValues[1]);

        String timePrd = null;
        String wk = null;


        if(null==timePeriod || timePeriod.isEmpty()){
            timePeriod= new ArrayList <String>();
            timePeriod.add("2");
        }
        if(null==weekWise || weekWise.isEmpty()){
            weekWise= new ArrayList <String>();
            weekWise.add("1");
        }
        if(Integer.parseInt(timePeriod.get(0))==2){
            timePrd="W";
            if(null==weekWiseSelection){
                if(Integer.parseInt(weekWise.get(0))==1){
                    wk="W1";
                }else if(Integer.parseInt(weekWise.get(0))==2){
                    wk="W2";
                }else {
                    wk="W3";
                }
            }else{
                wk=weekWiseSelection;
            }
        }

        ReportsBO.deleteProjectStatusWeekWise(wk,month,year,selectedArea);

    } catch (ApplicationException ex) {
        addActionError(ex.getMessage());
        fetchFields();
        return ERROR;
    }

    if(null!=weekWiseSelection || !weekWiseSelection.equalsIgnoreCase("month")){
        addActionMessage("Existing records are deleted and copied data from previous month.");
    }else{
        addActionMessage("Existing records are deleted and copied data from previous bi weekly.");
    }
    return SUCCESS;

和DAO类。

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    try {
        int projId = jdbcTemplate.queryForInt(ProjectStatus.FETCH_PROJECT_STATUS_WEEKWISE,new Object[] {week,month,year,areaId});
        jdbcTemplate.update(ProjectStatus.DELETE_PROJECT_DET_STATUS_MONTH,new Object[] {projId});
        jdbcTemplate.update(ProjectStatus.DELETE_PROJECT_STATUS_WEEKWISE,new Object[] {week,month,year,areaId});
    } catch (Exception e) {
        LOG.error("Exception occurred in dashboard.performance.gmu.dao.ProjectStatusDAO.fetchProjectStatusTypeList(int)",e);
        throw new ApplicationException("Failed to fetch project type list. Please contact System Administrator.");
    }

这个错误来了,任何人都可以帮助解决这个问题。

}

共有1个答案

朱和惬
2023-03-14

它看起来可能来自jdbctemplate.queryforint(...);。当预期结果至少有一行(或元素),但实际返回零行(或元素)时,将引发EmptyResultDataAccessException。检查以确保projid确实存在于数据库中。

 类似资料: