JdbcTemplate's queryForMap Method error

Source: Internet
Author: User
Tags oracle database
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

1 public void Test () {
2 String sql_get_attribute= "SELECT * from Test where rownum<1";
3 Map<object,object> map=getjdbctemplate (). queryForMap (Sql_get_attribute);
4 Set<entry<object, object>> entryset=map.entryset ();
5 For (Entry<object, object> entry:entryset) {
6 System.out.println ("key is" + Entry.getkey ());
7 System.out.println ("value is" + entry.getvalue ());
8 }
9 }

The output lists the test all fields key, the queried value is a string of Vlaue, where the Oracle database is used, forcing the use of "where rownum<1" to restrict the return of only one row.


The

takes 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, The workaround is to catch the exception and return null.  
Java code    try{                return getjdbctemplate (). queryForMap ("select s.fb,s.pb,s.tu,s.qt,s.fbc,s.pbc,s.tt,s.ft,s.lt &NBSP;FROM&NBSP;GBC$VIEW_USER&NBSP;S&NBSP;WHERE&NBSP;S.U

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.