JdbcTemplate queryForMap emptyresultdataaccessexception

Source: Internet
Author: User

JdbcTemplate's queryForMap Method error
Improper use of the queryForMap method will make an error, using the following methods:
The queryForMap method in JdbcTemplate is expects a single row to being returned, the return value for this method would be A map of column names to column values for the single result row.

The result set size returned by the queryForMap method must be 1, and the returned map, with the name of the column as the key, gets the value as

Take advantage of Spring's getjdbctemplate (). queryForMap If an empty set is returned, it will be reported
Org.springframework.dao.EmptyResultDataAccessException:Incorrect result size:expected 1, actual 0 exception
try{
Return Getjdbctemplate (). queryForMap ("Select s.fb,s.pb,s.tu,s.qt,s.fbc,s.pbc,s.tt,s.ft,s.lt from Gbc$view_user s where S.ud =? And ad=? ", New Object[]{ud,ad});
}catch (Emptyresultdataaccessexception e) {
return null;
}

Solution in the queryForMap place try catch a bit.

JdbcTemplate queryForMap emptyresultdataaccessexception

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.