ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Maves <nathan.ma...@gmail.com>
Subject Re: ibatis 3 COUNT -> Boolean
Date Wed, 04 Nov 2009 22:39:00 GMT
here is the java doc for how the resultset implementation should handle
this.  As long as your query will only return 0/1 you should be okay.  If
not, then I would just wrap the count() in an if and return a 1 if count was
more than 1.

I would also set both the jdbc type and the return type.  jdbcType to NUMBER
and Boolean for the Result.

Nathan


getBoolean

boolean *getBoolean*(int columnIndex)
                   throws SQLException
<http://java.sun.com/javase/6/docs/api/java/sql/SQLException.html>

Retrieves the value of the designated column in the current row of this
ResultSet object as a boolean in the Java programming language.

If the designated column has a datatype of CHAR or VARCHAR and contains a
"0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and
contains a 0, a value of false is returned. If the designated column has a
datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT,
TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is
returned.



On Wed, Nov 4, 2009 at 12:42 PM, Douglas Bell <DBell@boingo.com> wrote:

> I'm trying to do the following using beta 5 (this was working in beta 3)
>
> @Select("SELECT COUNT(username) FROM record WHERE username =
> #{username,jdbcType=VARCHAR}")
> Boolean isExisting(String username);
>
> I get a ClassCastException: java.lang.Long cannot be cast to
> java.lang.Boolean which is understandable.
>
> I thought adding a @Result(javaType = Boolean.class) would do it but I
> still get the same error. Can I do anything short of changing the return
> type to a Long and doing the conversion?
>
> Thanks
>
> -Doug
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Mime
View raw message