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

前端 未结 17 1253
执笔经年
执笔经年 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:01

    Ok, I figured it out. I just wrapped it in a try catch and send back null.

        public String test() {
                String cert=null;
                String sql = "select ID_NMB_SRZ from codb_owner.TR_LTM_SLS_RTN 
                         where id_str_rt = '999' and ID_NMB_SRZ = '60230009999999'";
                try {
                    Object o = (String) jdbc.queryForObject(sql, String.class);
                    cert = (String) o;
                } catch (EmptyResultDataAccessException e) {
                    e.printStackTrace();
                }
                return cert;
        }
    

提交回复
热议问题