将异常用作业务执行流程控制的合理用法,比较罕见:
- //判断某个表存不存在
- private boolean existTable(String table) {
- try{
- projectDAO.findBySql("select count(*) from "+table, null);
- return true;
- }catch (Exception e) {
- logger.info("执行判断表是否存在的SQL出错:"+"select count(*) from "+table+",原因:"+e.getMessage());
- return false;
- }
- }
但,在对性能不是很苛的场景应该也算合理吧。
不过,估计也会有正常的数据库查询语句,只是那样做,可能会导致不同的数据库写不同的查询语句吧。
转载于:https://blog.51cto.com/memory/1031627