You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Richard Grossman <ri...@goldmail.net.il> on 2003/03/31 14:51:33 UTC
How to select only 1 column from a table?
Hi,
I try to select only 1 column from a table using the peer object method DoSelect()
I've try:
Criteria crit = new Criteria();
crit.addSelectColumn(mainProductPeer.MAIN_PRODUCT_SEQID);
List SeqIDList = mainProductPeer.doSelect(crit);
I receive an Exception :
com.workingdogs.village.DataSetException: Only 1 columns exist!
Is it possible do this with Torque peer object?
If not is there another solution ?
Thanks
Richard
Re: How to select only 1 column from a table?
Posted by Eric Emminger <er...@ericemminger.com>.
Richard
> I try to select only 1 column from a table using the peer object method DoSelect()
> I've try:
> Criteria crit = new Criteria();
> crit.addSelectColumn(mainProductPeer.MAIN_PRODUCT_SEQID);
> List SeqIDList = mainProductPeer.doSelect(crit);
>
> I receive an Exception :
> com.workingdogs.village.DataSetException: Only 1 columns exist!
>
> Is it possible do this with Torque peer object?
I'm not sure. I've never done this myself. I just tried a similar select
to try to help you, but it failed as well. I'm guessing that Torque is
trying to turn the query into a List of *complete* objects, but since
only one column exists, it fails to set all the properties of the
objects. I'm going to ask about the intended use of addSelectColumn.
> If not is there another solution ?
I believe the other solution would be to use doSelectVillageRecords
instead of doSelect. That will return a List of
com.workingdogs.village.Record. So, to get a List of what you actually
want, you could do the following.
Criteria crit = new Criteria();
crit.addSelectColumn(mainProductPeer.MAIN_PRODUCT_SEQID);
List villageList = mainProductPeer.doSelectVillageRecords(crit);
List SeqIDList = new Vector();
Iterator it = villageList.iterator();
while (it.hasNext())
{
SeqIDList.add(new Integer(it.next().getValue(1).asInt()));
}
Note that Village records are 1-based, not 0-based, which is why you use
getValue(1) instead of getValue(0). Also, the above gives you a List of
Integer; use whatever you need.
Eric