spring jdbcTemplate how to catch exception?

后端 未结 3 1967
暖寄归人
暖寄归人 2020-12-31 03:39

Everything is brilliant until I encounter place where I actually do need to catch exception. When I place

jdbcTemplate.query(something...)

3条回答
  •  长情又很酷
    2020-12-31 04:07

    You should catch the JdbcTemplate exception

    i.e.

    try
    {
       // Your Code 
    }
    catch (InvalidResultSetAccessException e) 
    {
        throw new RuntimeException(e);
    } 
    catch (DataAccessException e)
    {
        throw new RuntimeException(e);
    }
    

提交回复
热议问题