Spring NamedParameterJdbcTemplate not returning result for simple query

£可爱£侵袭症+ 提交于 2019-12-13 07:57:43

问题


Please bare with my limited info on code since having limited access to copy paste complete code.

@Repository("BaseDao")
public class BaseDaoImpl implements BaseDao{

public NamedParameterJdbcTemplate namedJdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource){
 this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
 }
}

@Repository("WelcomeDao")
public class WelcomeDaoImpl extends BaseDaoImpl implements WelcomeDao {

 public List<String> getFunctionTypes() {
  SqlParameterSource paramSource = new MapSqlParameterSource();
  paramSource .addValue("function_id", "FRS047");
  paramSource .addValue("user_id", "DWHJAVA");

String query = "select distinct FUNCTION_TYPE from EX_VIEW where FUNCTION_ID = :function_id and USER_ID = :user_id ";

List<String> funTypes = this.namedJdbcTemplate.queryForList(query, paramSource,String.class);
return funTypes; 
 }
}

I also tried replacing SqlParameterSource with plain Map but no luck!!

I cannot get the results by executing the above query whereas instead of named parameters if I replace with hardcoded values in query, am able to retrieve the results!!

Please help what's wrong with my way of substituting parameters?

I frustrated and finally want to give up NamedParameterJdbcTemplate..

来源:https://stackoverflow.com/questions/29924774/spring-namedparameterjdbctemplate-not-returning-result-for-simple-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!