Java org.springframework.dao.EmptyResultDataAccessException:结果大小不正确:预期为 1,实际为 0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28671579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
提问by Sudhakar J
i'm this following error when i submit for copying data here is the code..
当我提交复制数据时出现以下错误,这是代码..
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;
and DAO class..
和 DAO 类..
public void deleteProjectStatusWeekWise(String week,int month,int year,String area) throws ApplicationException { int areaId=Integer.parseInt(area);
public void deleteProjectStatusWeekWise(String week,int month,int year,String area) 抛出 ApplicationException { int areaId=Integer.parseInt(area);
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.");
}
}
}
this error is coming can anyone help on this to resolve the issue.
这个错误即将到来,任何人都可以帮助解决这个问题。
}
回答by Shaggy
It looks like it is probably coming from jdbcTemplate.queryForInt(...);. An EmptyResultDataAccessExceptionis thrown when a result was expected to have at least one row (or element) but zero rows (or elements) were actually returned. Check to make sure the projIdactually exists in the database.
看起来它很可能来自jdbcTemplate.queryForInt(...);. 一个EmptyResultDataAccessException当结果被预期具有至少一排(或元件),但零行(或元件)的实际返回被抛出。检查以确保projId实际存在于数据库中。

