Announcement Announcement Module
Collapse
No announcement yet.
[iBatis] DAO throws SqlException or DAO Catch sqlException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [iBatis] DAO throws SqlException or DAO Catch sqlException

    I have the following DAO implementation:

    Code:
    public class UserDAOImpl extends SqlMapClientDaoSupport implements UserDAO {
    
        public User load(String username, String password) {
            String passHash = MD5.getHash(password);
            final Map map = new HashMap();
            map.put("username", username);
            map.put("password", passHash);
    
            try{
                return (User)getSqlMapClient().queryForObject("getUser", map);
            }catch(SQLException sqlE){
                sqlE.printStackTrace();
                return null;
            }
        }
    }
    Ignoring the fact that what I am doing in my catch block is bad bad bad, should I be doing the try/catch in the DAO like this, or should the DAO method load throw an SqlException and I catch that in my calling method?

    Thanks.

  • #2
    Take a look at using getSqlMapClientTemplate().

    You can then let SqlMapClientTemplate automatically convert checked SQLExceptions into unchecked DataAccessExceptions.

    Comment


    • #3
      Originally posted by katentim
      Take a look at using getSqlMapClientTemplate() .
      :wink: Wondered if I was missing something like this. Thanks.

      Comment

      Working...
      X