2010.10.09(2)———SimpleJdbcTemplate的queryForObject问题

2010.10.09(2)———SimpleJdbcTemplate的queryForObject问题

今天发现
SimpleJdbcTemplate.queryForObject(sql,ParameterizedBeanPropertyRowMapper.newInstance(GC_SGXKZ.class), gcbm);


当从数据库里面没有查到数据时 不会返回一null 而是会抛出一个EmptyResultDataAccessException异常 这个很郁闷

所以在action里面最好要捕获一下 要不就会报错了


GC_SGXKZ o = null;
		try{
			o = this.GC_SGXKZService.findByGcbm(gcbm);
		}catch(Exception e){
			o = null;
		}









你可能感兴趣的:(java,sql)