You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Edwin S Lukaweski <se...@rogers.com> on 2005/12/04 23:45:12 UTC

DAO catch SQLexceptions

I am using Ibatis Data Access Objects. I cannot figure out how to catch SQLExceptions when using methods like "group = (Group)queryForObject("getGroup", oid);"

    I wish to catch the fact that a row may not exist and report the error back to the user. The Data Mapper seems to provide SQLExceptions bu the DAO methods do not.

    Any help would be appreciated.

Edwin

Re: DAO catch SQLexceptions

Posted by Zarar Siddiqi <za...@utoronto.ca>.
Some database drivers might even return an error code as part of the 
Exception.  You can examine that and find out exactly what went wrong.  For 
example, IBM's DB2 has a mapping of "error code" => "what went wrong".

http://publib.boulder.ibm.com/infocenter/db2help/index.jsp?topic=/com.ibm.db2.udb.doc/ad/rjvjcsqc.htm



----- Original Message ----- 
From: "Edwin S Lukaweski" <se...@rogers.com>
To: <us...@ibatis.apache.org>
Sent: Monday, December 05, 2005 7:20 AM
Subject: Re: DAO catch SQLexceptions


> OK. I had a closer look and found it. It seems that there is an exception 
> thrown, "DaoException", that can be caught and acted upon. This is what 
> I'll use.
>
> Thnaks, again, for the response.
>
> Edwin
>
> ----- Original Message ----- 
> From: "Edwin S Lukaweski" <se...@rogers.com>
> To: <us...@ibatis.apache.org>; <lm...@apache.org>
> Sent: Monday, December 05, 2005 6:31 AM
> Subject: Re: DAO catch SQLexceptions
>
>
>>    Thank you for the prompt answer. You are right. The specific situation 
>> I described will return null.
>>
>>    That still leaves the question, in my mind, about catching 
>> SQLExceptions in general. There may be other situations that cause an 
>> SQLException, such as an invalid SELECT statement. Is there a way of 
>> catching these?
>>
>> thanks,
>> Edwin
>>
>> ----- Original Message ----- 
>> From: "Larry Meadors" <lm...@apache.org>
>> To: <us...@ibatis.apache.org>
>> Sent: Sunday, December 04, 2005 6:19 PM
>> Subject: Re: DAO catch SQLexceptions
>>
>>
>> That would not throw an exception anyway - the returned object would
>> simply be null.
>>
>> Larry
>>
>>
>> On 12/4/05, Edwin S Lukaweski <se...@rogers.com> wrote:
>>>
>>>
>>> I am using Ibatis Data Access Objects. I cannot figure out how to catch
>>> SQLExceptions when using methods like "group =
>>> (Group)queryForObject("getGroup", oid);"
>>>
>>>     I wish to catch the fact that a row may not exist and report the 
>>> error
>>> back to the user. The Data Mapper seems to provide SQLExceptions bu the 
>>> DAO
>>> methods do not.
>>>
>>>     Any help would be appreciated.
>>>
>>> Edwin
>>
>>
>>
>
>
> 



Re: DAO catch SQLexceptions

Posted by Edwin S Lukaweski <se...@rogers.com>.
OK. I had a closer look and found it. It seems that there is an exception 
thrown, "DaoException", that can be caught and acted upon. This is what I'll 
use.

Thnaks, again, for the response.

Edwin

----- Original Message ----- 
From: "Edwin S Lukaweski" <se...@rogers.com>
To: <us...@ibatis.apache.org>; <lm...@apache.org>
Sent: Monday, December 05, 2005 6:31 AM
Subject: Re: DAO catch SQLexceptions


>    Thank you for the prompt answer. You are right. The specific situation 
> I described will return null.
>
>    That still leaves the question, in my mind, about catching 
> SQLExceptions in general. There may be other situations that cause an 
> SQLException, such as an invalid SELECT statement. Is there a way of 
> catching these?
>
> thanks,
> Edwin
>
> ----- Original Message ----- 
> From: "Larry Meadors" <lm...@apache.org>
> To: <us...@ibatis.apache.org>
> Sent: Sunday, December 04, 2005 6:19 PM
> Subject: Re: DAO catch SQLexceptions
>
>
> That would not throw an exception anyway - the returned object would
> simply be null.
>
> Larry
>
>
> On 12/4/05, Edwin S Lukaweski <se...@rogers.com> wrote:
>>
>>
>> I am using Ibatis Data Access Objects. I cannot figure out how to catch
>> SQLExceptions when using methods like "group =
>> (Group)queryForObject("getGroup", oid);"
>>
>>     I wish to catch the fact that a row may not exist and report the 
>> error
>> back to the user. The Data Mapper seems to provide SQLExceptions bu the 
>> DAO
>> methods do not.
>>
>>     Any help would be appreciated.
>>
>> Edwin
>
>
> 



Re: DAO catch SQLexceptions

Posted by Edwin S Lukaweski <se...@rogers.com>.
    Thank you for the prompt answer. You are right. The specific situation I 
described will return null.

    That still leaves the question, in my mind, about catching SQLExceptions 
in general. There may be other situations that cause an SQLException, such 
as an invalid SELECT statement. Is there a way of catching these?

thanks,
Edwin

----- Original Message ----- 
From: "Larry Meadors" <lm...@apache.org>
To: <us...@ibatis.apache.org>
Sent: Sunday, December 04, 2005 6:19 PM
Subject: Re: DAO catch SQLexceptions


That would not throw an exception anyway - the returned object would
simply be null.

Larry


On 12/4/05, Edwin S Lukaweski <se...@rogers.com> wrote:
>
>
> I am using Ibatis Data Access Objects. I cannot figure out how to catch
> SQLExceptions when using methods like "group =
> (Group)queryForObject("getGroup", oid);"
>
>     I wish to catch the fact that a row may not exist and report the error
> back to the user. The Data Mapper seems to provide SQLExceptions bu the 
> DAO
> methods do not.
>
>     Any help would be appreciated.
>
> Edwin



Re: DAO catch SQLexceptions

Posted by Larry Meadors <lm...@apache.org>.
That would not throw an exception anyway - the returned object would
simply be null.

Larry


On 12/4/05, Edwin S Lukaweski <se...@rogers.com> wrote:
>
>
> I am using Ibatis Data Access Objects. I cannot figure out how to catch
> SQLExceptions when using methods like "group =
> (Group)queryForObject("getGroup", oid);"
>
>     I wish to catch the fact that a row may not exist and report the error
> back to the user. The Data Mapper seems to provide SQLExceptions bu the DAO
> methods do not.
>
>     Any help would be appreciated.
>
> Edwin