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 c....@ads.it on 2006/11/23 15:11:10 UTC
Single column select
Hi all
let's consider a very simple select whose purpose is to extract a column
of basic type.
E.g.
select MY_COLUMN
from MY_TABLE
for a list of values such as...
24
19
20
24
30
25
...
( a set if the distinct specification would be used)
(MY_COLUMN in this case is either of INTEGER or NUMERIC type)
How should I define the SQL map?
I've just read the "Implicit Result Maps" in the developer guide but I have
not found any similar example (single column selection). All examples
report cases of
select *
or
select COLUMN_1, COLUMN_2, ...
It's not a primitive result but, instead, a list (or set) of primitive
results.
Instinctively I would exclude an HashMap, because, definitively, return
values are not named and cannot be accessed via keys.
Should I anyway define a single property class / result map and use it
along with queryForList?
Or is there any simpler way?
ciao
Re: Single column select !
Posted by c....@ads.it.
larry.meadors@gmail.com scritti il 23/11/2006 15:17:37
> <select id="gah" resultclass="int">
> select blah as value from sometable
> </select>
Thanks, Larry. It works.
The following java code exerts successfully that SQL Map
List<Integer> lList = null;
try
{
lList = (List<Integer>) lSqlMapClient.queryForList( "gah", null );
}
catch ( SQLException pException )
{
pException.printStackTrace();
throw pException;
}
...
Re: Single column select
Posted by Larry Meadors <lm...@apache.org>.
<select id="gah" resultclass="int">
select blah as value from sometable
</select>
On 11/23/06, c.zecca@ads.it <c....@ads.it> wrote:
>
>
> Hi all
>
> let's consider a very simple select whose purpose is to extract a column of
> basic type.
> E.g.
>
> select MY_COLUMN
> from MY_TABLE
>
> for a list of values such as...
>
> 24
> 19
> 20
> 24
> 30
> 25
> ...
> ( a set if the distinct specification would be used)
>
> (MY_COLUMN in this case is either of INTEGER or NUMERIC type)
> How should I define the SQL map?
> I've just read the "Implicit Result Maps" in the developer guide but I have
> not found any similar example (single column selection). All examples report
> cases of
>
> select *
>
> or
>
> select COLUMN_1, COLUMN_2, ...
>
>
> It's not a primitive result but, instead, a list (or set) of primitive
> results.
> Instinctively I would exclude an HashMap, because, definitively, return
> values are not named and cannot be accessed via keys.
>
> Should I anyway define a single property class / result map and use it
> along with queryForList?
> Or is there any simpler way?
>
> ciao