Incorrect result size: Expected 1, actual 0 error and Solution

Source: Internet
Author: User

The error is as follows:
Org. springframework. Dao. incorrectresultsizedataaccessexception: incorrect result size: Expected 1, actual 0

In spring javadoc, GetObject (string, object [], class) will return NULL if the result of the query is NUL
There is a difference between line 0 and nullresult.
Row 0: Select salary from user where 1 = 2
Null result: Select max (salary) from user where 1 = 2 returns NULL
Row 0 must throw an incorrectresultsizedataaccessexception exception.
The reason is as follows:
Resultsetmetadata rsmd = Rs. getmetadata ();
Int nrofcolumns = rsmd. getcolumncount (); the number of columns in resultset is returned.
If (nrofcolumns! = 1 ){
Throw new incorrectresultsizedataaccessexception (
"Expected single column but found" + nrofcolumns, 1, nrofcolumns );
}
If there are 0 rows and more than 1 row, an exception is thrown.
It is better to use queryforlist. The returned list size is 0, which is 0 rows.

Re: http://www.xml.org.cn/blog/more.asp? Name = hongrui and ID = 9521

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.