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 John Moore <jo...@jmsd.co.uk> on 2006/05/11 18:57:51 UTC
Generate a list of Integers?
I'm just getting into Ibatis and am enjoying using it. I now have what
is probably rather a dumb question. Hitherto I have been using result
maps with my own classes, so Ibatis maps database columns to properties
in my class. I now want to have Ibatis simply return me a list of
Integers. I have a table with an id column, defined as int, and I simply
want a list of those ids. How do I do this? I'm getting a bit confused
with resultMaps and resultClasses.
TIA,
John
--
==============================================
John Moore - Norwich, UK - john@jmsd.co.uk
==============================================
Re: Generate a list of Integers?
Posted by Ted Schrader <ts...@gmail.com>.
Smashing.
Yeah, usage of queryForList() versus queryForObject() will dictate
whether you get a List or an Integer. That said, don't use this
query with queryForObject() because it will blow up since there's more
than one record.
Cheers,
Ted
On 11/05/06, John Moore <jo...@jmsd.co.uk> wrote:
> Ted Schrader wrote:
>
> > Hi John,
> >
> > I'm not sure if this will do it, but try this:
> >
> > <select id="myQuery" resultClass="java.lang.Integer">
> > SELECT id
> > FROM ID_TABLE
> > </select>
> >
> Spot on! It worked fine, thanks. I was getting confused about what the
> result class meant, as this actually returns a List of Integers, not an
> Integer.
>
> John
>
>
> --
> ==============================================
> John Moore - Norwich, UK - john@jmsd.co.uk
> ==============================================
>
Re: Generate a list of Integers?
Posted by John Moore <jo...@jmsd.co.uk>.
Ted Schrader wrote:
> Hi John,
>
> I'm not sure if this will do it, but try this:
>
> <select id="myQuery" resultClass="java.lang.Integer">
> SELECT id
> FROM ID_TABLE
> </select>
>
Spot on! It worked fine, thanks. I was getting confused about what the
result class meant, as this actually returns a List of Integers, not an
Integer.
John
--
==============================================
John Moore - Norwich, UK - john@jmsd.co.uk
==============================================
Re: Generate a list of Integers?
Posted by Ted Schrader <ts...@gmail.com>.
Hi John,
I'm not sure if this will do it, but try this:
<select id="myQuery" resultClass="java.lang.Integer">
SELECT id
FROM ID_TABLE
</select>
Ted
On 11/05/06, John Moore <jo...@jmsd.co.uk> wrote:
> I'm just getting into Ibatis and am enjoying using it. I now have what
> is probably rather a dumb question. Hitherto I have been using result
> maps with my own classes, so Ibatis maps database columns to properties
> in my class. I now want to have Ibatis simply return me a list of
> Integers. I have a table with an id column, defined as int, and I simply
> want a list of those ids. How do I do this? I'm getting a bit confused
> with resultMaps and resultClasses.
>
> TIA,
>
> John
>
>
>
> --
> ==============================================
> John Moore - Norwich, UK - john@jmsd.co.uk
> ==============================================
>