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
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 ()); |
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