ufoer23

Incorrect result size: expected 1, actual 0错误以及解决方法

错误如下:
org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size: expected 1, actual 0

springjavadoc上讲getObject(String, Object[], Class) will return NULL if the result of the query is NUL
这里有0行和nullresult的区别
0
: select salary from user where 1 = 2
null result: select max(salary) from user where 1 = 2
返回就是null
0
行一定抛出IncorrectResultSizeDataAccessException异常
原因如下
ResultSetMetaData rsmd = rs.getMetaData();
int nrOfColumns = rsmd.getColumnCount();
这里返回ResultSet的列数
  if (nrOfColumns != 1) {
   throw new IncorrectResultSizeDataAccessException(
     "Expected single column but found " + nrOfColumns, 1, nrOfColumns);
  }
0
,多于1,就抛异常了
 
最好还是用QueryForList,返回的listsize0,就是0

转载:http://www.xml.org.cn/blog/more.asp?name=hongrui&id=9521

posted on 2005-11-29 09:56  不明飞行物  阅读(44334)  评论(1编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-12-02
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2021-07-22
猜你喜欢
  • 2021-12-13
  • 2021-04-19
  • 2021-06-06
  • 2021-12-27
相关资源
相似解决方案