Jdbctemplate query for string: EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0

前端 未结 17 1241
执笔经年
执笔经年 2020-11-29 16:22

I am using Jdbctemplate to retrieve a single String value from the db. Here is my method.

    public String test() {
        String cert=null;
        Strin         


        
17条回答
  •  日久生厌
    2020-11-29 17:10

    Since getJdbcTemplate().queryForMap expects minimum size of one but when it returns null it shows EmptyResultDataAccesso fix dis when can use below logic

    Map loginMap =null;
    try{
        loginMap = getJdbcTemplate().queryForMap(sql, new Object[] {CustomerLogInInfo.getCustLogInEmail()});
    }
    catch(EmptyResultDataAccessException ex){
        System.out.println("Exception.......");
        loginMap =null;
    }
    if(loginMap==null || loginMap.isEmpty()){
        return null;
    }
    else{
        return loginMap;
    }
    

提交回复
热议问题