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 pc leung <pi...@gmail.com> on 2005/11/30 14:28:20 UTC

How to return a List of record?

In table xml file, I try to return a List.
Is it able to return a List of object of record?
(I have this question because I find the return a single record have
the very similar setup)

Thanks

table xml file

  <select id="getUserProfileList" parameterClass="string"
resultMap="userProfileResult">
    select usernm, passwd, eng_name, chi_name, dob, join_date,
           creation_date, created_by, last_update_date, last_update_by
      from user_profile
     where usernm = #usernm#
  </select>


table SqlMapDao file
public class UserProfileSqlMapDao extends BaseSqlMapDao implements
UserProfileDao {
...
	public List getUserProfileList(String usernm) {
		return super.queryForList("getUserProfileList", usernm);
	}

Re: How to return a List of record?

Posted by Gary Bradshaw <gb...@davisvision.com>.
Boy, was my first answer off base! Sorry about that. If I may try again...

Sure, you can use the same select to retrieve both a record (via 
queryForObject) and a list containing one record (via queryForList).

   - gary


At 08:30 PM 11/30/2005, you wrote:
>I want to get a List of records by getUserProfileList.
>This is my UserProfile.xml.
>
>   <select id="getUserProfileList" parameterClass="string"
>resultMap="userProfileResult">select usernm, passwd, eng_name,
>chi_name, dob, join_date, creation_date, created_by, last_update_date,
>last_update_by from user_profile where usernm = #usernm#</select>
>
>   <select id="getUserProfile" parameterClass="string"
>resultMap="userProfileResult">select usernm, passwd, eng_name,
>chi_name, dob, join_date, creation_date, created_by, last_update_date,
>last_update_by from user_profile where usernm = #usernm#</select>
>
>I hope the first one can return a List of records and the second one
>can return a single record. The only difference lies in SqlMapDao. Are
>they okay?
>
>
>On 12/1/05, Nathan Maves <Na...@sun.com> wrote:
> > What you have would work perfectly if you have more then one row in
> > your database that have the same "usernm".  I am not sure that this
> > is really what you want.  If not take out your where clause and you
> > will get a result (java.util.List) of all of your users.
> >
> > Nathan
> >
> > On Nov 30, 2005, at 6:28 AM, pc leung wrote:
> >
> > > In table xml file, I try to return a List.
> > > Is it able to return a List of object of record?
> > > (I have this question because I find the return a single record have
> > > the very similar setup)
> > >
> > > Thanks
> > >
> > > table xml file
> > >
> > >   <select id="getUserProfileList" parameterClass="string"
> > > resultMap="userProfileResult">
> > >     select usernm, passwd, eng_name, chi_name, dob, join_date,
> > >            creation_date, created_by, last_update_date, last_update_by
> > >       from user_profile
> > >      where usernm = #usernm#
> > >   </select>
> > >
> > >
> > > table SqlMapDao file
> > > public class UserProfileSqlMapDao extends BaseSqlMapDao implements
> > > UserProfileDao {
> > > ...
> > >       public List getUserProfileList(String usernm) {
> > >               return super.queryForList("getUserProfileList", usernm);
> > >       }
> >
> >



------------------------------------------------------------------------
The information contained in this communication is intended
only for the use of the recipient(s) named above. It may
contain information that is privileged or confidential, and
may be protected by State and/or Federal Regulations. If
the reader of this message is not the intended recipient,
you are hereby notified that any dissemination,
distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received
this communication in error, please return it to the sender
immediately and delete the original message and any copy
of it from your computer system. If you have any questions
concerning this message, please contact the sender.
------------------------------------------------------------------------

Re: How to return a List of record?

Posted by pc leung <pi...@gmail.com>.
I want to get a List of records by getUserProfileList.
This is my UserProfile.xml.

  <select id="getUserProfileList" parameterClass="string"
resultMap="userProfileResult">select usernm, passwd, eng_name,
chi_name, dob, join_date, creation_date, created_by, last_update_date,
last_update_by from user_profile where usernm = #usernm#</select>

  <select id="getUserProfile" parameterClass="string"
resultMap="userProfileResult">select usernm, passwd, eng_name,
chi_name, dob, join_date, creation_date, created_by, last_update_date,
last_update_by from user_profile where usernm = #usernm#</select>

I hope the first one can return a List of records and the second one
can return a single record. The only difference lies in SqlMapDao. Are
they okay?


On 12/1/05, Nathan Maves <Na...@sun.com> wrote:
> What you have would work perfectly if you have more then one row in
> your database that have the same "usernm".  I am not sure that this
> is really what you want.  If not take out your where clause and you
> will get a result (java.util.List) of all of your users.
>
> Nathan
>
> On Nov 30, 2005, at 6:28 AM, pc leung wrote:
>
> > In table xml file, I try to return a List.
> > Is it able to return a List of object of record?
> > (I have this question because I find the return a single record have
> > the very similar setup)
> >
> > Thanks
> >
> > table xml file
> >
> >   <select id="getUserProfileList" parameterClass="string"
> > resultMap="userProfileResult">
> >     select usernm, passwd, eng_name, chi_name, dob, join_date,
> >            creation_date, created_by, last_update_date, last_update_by
> >       from user_profile
> >      where usernm = #usernm#
> >   </select>
> >
> >
> > table SqlMapDao file
> > public class UserProfileSqlMapDao extends BaseSqlMapDao implements
> > UserProfileDao {
> > ...
> >       public List getUserProfileList(String usernm) {
> >               return super.queryForList("getUserProfileList", usernm);
> >       }
>
>

Re: How to return a List of record?

Posted by Nathan Maves <Na...@Sun.COM>.
What you have would work perfectly if you have more then one row in  
your database that have the same "usernm".  I am not sure that this  
is really what you want.  If not take out your where clause and you  
will get a result (java.util.List) of all of your users.

Nathan

On Nov 30, 2005, at 6:28 AM, pc leung wrote:

> In table xml file, I try to return a List.
> Is it able to return a List of object of record?
> (I have this question because I find the return a single record have
> the very similar setup)
>
> Thanks
>
> table xml file
>
>   <select id="getUserProfileList" parameterClass="string"
> resultMap="userProfileResult">
>     select usernm, passwd, eng_name, chi_name, dob, join_date,
>            creation_date, created_by, last_update_date, last_update_by
>       from user_profile
>      where usernm = #usernm#
>   </select>
>
>
> table SqlMapDao file
> public class UserProfileSqlMapDao extends BaseSqlMapDao implements
> UserProfileDao {
> ...
> 	public List getUserProfileList(String usernm) {
> 		return super.queryForList("getUserProfileList", usernm);
> 	}


Re: How to return a List of record?

Posted by Gary Bradshaw <gb...@davisvision.com>.
Without seeing your userProfileResult map definition, it's hard to tell 
exactly what you're trying to do. If you just want a list of Objects 
without any field names, I don't think iBatis will do that. It will, 
however, return a Map keyed by the field names if you say 
resultClass="java.util.Map", so you could use SQL column aliases to get 
names like C01, C02, etc. and then construct a List from the Map. E.g.

      select usernm as c00, passwd as c01, eng_name as c02, ...

Does this help?

   - gary

At 08:28 AM 11/30/2005, you wrote:
>In table xml file, I try to return a List.
>Is it able to return a List of object of record?
>(I have this question because I find the return a single record have
>the very similar setup)
>
>Thanks
>
>table xml file
>
>   <select id="getUserProfileList" parameterClass="string"
>resultMap="userProfileResult">
>     select usernm, passwd, eng_name, chi_name, dob, join_date,
>            creation_date, created_by, last_update_date, last_update_by
>       from user_profile
>      where usernm = #usernm#
>   </select>
>
>
>table SqlMapDao file
>public class UserProfileSqlMapDao extends BaseSqlMapDao implements
>UserProfileDao {
>...
>         public List getUserProfileList(String usernm) {
>                 return super.queryForList("getUserProfileList", usernm);
>         }



------------------------------------------------------------------------
The information contained in this communication is intended
only for the use of the recipient(s) named above. It may
contain information that is privileged or confidential, and
may be protected by State and/or Federal Regulations. If
the reader of this message is not the intended recipient,
you are hereby notified that any dissemination,
distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received
this communication in error, please return it to the sender
immediately and delete the original message and any copy
of it from your computer system. If you have any questions
concerning this message, please contact the sender.
------------------------------------------------------------------------