JdbcTemplate的queryForMap方法报错
2013-01-14 00:00
477 查看
JdbcTemplate的queryForMap方法报错
queryForMap方法使用不当,就会出错,使用方式如下:
The queryForMap method in JdbcTemplate only expects a single row to be returned, The return value for this method will be a map of column names to column values for the single result row.
queryForMap方法返回的结果集大小必须是1,并且返回的map中,以列的名字作为key,获取的值作为value
输出会列出test所有字段为key,查询出来的值为vlaue的字符串,这里使用oracle数据库,强制使用“where rownum<1”来限制只返回一行。
queryForMap方法使用不当,就会出错,使用方式如下:
The queryForMap method in JdbcTemplate only expects a single row to be returned, The return value for this method will be a map of column names to column values for the single result row.
queryForMap方法返回的结果集大小必须是1,并且返回的map中,以列的名字作为key,获取的值作为value
public void test(){ String SQL_GET_ATTRIBUTE="select * from test where rownum<1"; Map<Object,Object> map=getJdbcTemplate().queryForMap(SQL_GET_ATTRIBUTE); Set<Entry<Object, Object>> entrySet=map.entrySet(); for (Entry<Object, Object> entry : entrySet) { System.out.println("key is " + entry.getKey()); System.out.println("value is " + entry.getValue()); } }
输出会列出test所有字段为key,查询出来的值为vlaue的字符串,这里使用oracle数据库,强制使用“where rownum<1”来限制只返回一行。
相关文章推荐
- org.springframework.jdbc.core.simple.SimpleJdbcTemplate queryForMap 方法在查询结果为空时抛出异常
- JdbcTemplate的queryForMap方法报错
- jdbcTemplate.queryForInt()过时替换方法
- 2015061204 - jdbctemplate中的queryForIntf方法
- JdbcTemplate中的exectue和queryForList方法的性能对比
- Spring中JDBCTemplate使用queryForObject方法时 ”Incorrect column count: expected 1, actual 5“错误
- JdbcTemplate中的queryForMap和queryForObject的异常
- JdbcTemplate queryForMap EmptyResultDataAccessException
- 关于mysql 数据库使用spring 2.0低版本 JdbcTemplate.queryForList 查询结果别名不起作用的解决方法
- 在使用JdbcTemplate.queryForMap(String )的时候发现一个问题.
- JdbcTemplate.queryForList()方法各不同参数的详解
- jdbcTemplate.queryForObject 方法注意
- 通过iBatis的queryForMap方法比较resultClass与resultMap
- Spring中使用JdbcTemplate的queryForObject方法,当查不到数据时会抛出如下异常:
- 通过iBatis的queryForMap方法比较resultClass与resultMap
- ibatis的queryForMap方法的使用与实现
- ibatis的queryForMap方法研究
- The method queryForMap(String, Object...) from the type JdbcTemplate refers to the missing type DataAccessException
- 通过iBatis的queryForMap方法比较resultClass与resultMap
- 通过iBatis的queryForMap方法比较resultClass与resultMap