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

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

    IMHO returning a null is a bad solution because now you have the problem of sending and interpreting it at the (likely) front end client. I had the same error and I solved it by simply returning a List. I used JDBCTemplate.query().

    At the front end (Angular web client), I simply examine the list and if it is empty (of zero length), treat it as no records found.

提交回复
热议问题