ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sundar Sankar <fatboys...@gmail.com>
Subject Re: error handling in iBatis?
Date Mon, 11 May 2009 16:08:42 GMT
I guess you can use the same kinda code to catch exception. I batis does
throw SQLException for errors. If you are using Spring, then it is wrapped
to something else (DAOException, I think). You could throw back custom
exception or a new SQLException when the size doesnt match ur need.

I would have written Unit test for the same and tested out the erroneous
cases to make sure of what I was getting!

Let us know if it didnt work

-Sundar

On Mon, May 11, 2009 at 8:26 AM, Bhaarat Sharma <bhaarat.s@gmail.com> wrote:

> we have been using iBatis for a while now.
> However, we do not perform any error handling while executing the sql maps.
>  Back when we used java code to connect, we used try and catch blocks.
>  Where the catch block would log an error message.
>
> something like this:
>
>             try {
>                 Conn = getConnection(DataCollection.HEREMS);
>                 cstmt = Conn.prepareCall(storProc);
>                 cstmt.setString(1, user.toUpperCase());
>                 rs = cstmt.executeQuery();
>                 while (rs.next()) {
>                     String roleId = rs.getString("role_code");
>                     Roles.add(roleId);
>                 }
>             }catch (SQLException ex) {
>                 log.error(ex.getMessage(),ex);
>             }finally {
>                try {
>                   releaseConnection(Conn, cstmt, null, rs);
>                }catch (SQLException ex) {
>                 log.error(ex.getMessage(),ex);
>                }
>             }
>
> Now with sqlMaps we simply do something like this:
>
>         getSqlMapClientTemplate().queryForList("debtowed.getSingleTenant",
> paramMap);
>
>         if (paramMap.size() == 3)
>         {
>             fmr = (FormerTenants) paramMap.get("single_tenant_results");
>
>  fmr.setTerminationReason(paramMap.get("single_tenant_rejection_results"));
>         }
>
>         return fmr;
>
> In the above code we are expecting 3 resultsets so all we are doing is
> checking if map size is 3.
>
> What if some error happens while executing the stored procedure.  Where
> will that error go?  Is there a way in iBatis to log error messages? I would
> appreciate some sample which would point me in the right direction.
>
> Thanks
>

Mime
View raw message