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 xianwinwin <xi...@gmail.com> on 2006/06/15 00:38:52 UTC

IN (SQL), how to iterate?

can anyone provide an exmple of how to use this statement with iBatis?

    	SELECT name,branch,username 
        FROM KXAccount
    	WHERE id IN ('234','655','411','775,'416')

the problem is in the IN clause: when I try this:

    	    	SELECT name,branch,username 
                FROM KXAccount
    	        WHERE id IN (#ids#)

I try this and while popuplating the #ids# with a string of:
'234','655','411','775,'416' 
the result applies only to the first item (234).

does anyone know any exmple of IN which iterate through the object?
thanks


--
View this message in context: http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4874196
Sent from the iBATIS - User - Java forum at Nabble.com.


Re: IN (SQL), how to iterate?

Posted by puneet arya <pu...@yahoo.co.in>.
ok i didnt try iterate tag . may be it works more better .
                                                                  Puneet arya

Jeff Butler <je...@gmail.com> wrote:
    This could work, but it's not the best way to do it.  You loose all the type capabilities of iBATIS and some types are not so easy to convert to strings.  It's much better to use the <iterate> tag.
   
  Jeff Butler

 
  On 6/15/06, puneet arya <pu...@yahoo.co.in> wrote:       hi,
  
   SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)

  You can write in xml as 
   
  
     SELECT name,branch,username
               FROM KXAccount

                 WHERE id IN ($ids$)
   
  and in these id you have to capture as a string . if u didnt get , you just tell me teh full scenario i will give you the exact solution.




       eg sql: 
     
      SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)

 you can write as this:
   
   
      SELECT name,branch,username
               FROM KXAccount
     <iterate prepend="where" property="ids"open=" id in (" conjunction="," close=")" >
    #ids[]#
   </iterate>

 
  2006/6/15, xianwinwin <xi...@gmail.com>:   
can anyone provide an exmple of how to use this statement with iBatis?

       SELECT name,branch,username 
       FROM KXAccount
       WHERE id IN ('234','655','411','775,'416')

the problem is in the IN clause: when I try this:

               SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)

I try this and while popuplating the #ids# with a string of:
'234','655','411','775,'416'
the result applies only to the first item (234).

does anyone know any exmple of IN which iterate through the object? 
thanks


--
View this message in context: http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4874196 
Sent from the iBATIS - User - Java forum at Nabble.com.





-- 
RenZenggang
Renzenggang@gmail.com 
Renzenggang@csii.com
MSN:rzg117@hotmail.com
Blog: http://rzg.itpub.net


    Send instant messages to your online friends http://in.messenger.yahoo.com 

Stay connected with your friends even when away from PC. Link: http://in.mobile.yahoo.com/new/messenger/   
  

    
---------------------------------
  Yahoo! India Answers: Share what you know. Learn something new Click here
Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download now 
    
  





 				
---------------------------------
  Yahoo! India Answers: Share what you know. Learn something new Click here
 Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download now
 				
---------------------------------
  Yahoo! India Answers: Share what you know. Learn something new Click here
 Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download now

Re: IN (SQL), how to iterate?

Posted by Jeff Butler <je...@gmail.com>.
This could work, but it's not the best way to do it.  You loose all the type
capabilities of iBATIS and some types are not so easy to convert to
strings.  It's much better to use the <iterate> tag.

Jeff Butler


On 6/15/06, puneet arya <pu...@yahoo.co.in> wrote:
>
>  hi,
>   SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN (#ids#)
> You can write in xml as
>
>     SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN ($ids$)
>
> and in these id you have to capture as a string . if u didnt get , you
> just tell me teh full scenario i will give you the exact solution.
>
>
> **
>
>  eg sql:
>
>     SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN (#ids#)
>
>  you can write as this:
>
>
>     SELECT name,branch,username
>                FROM KXAccount
>    <iterate prepend="where" property="ids"open=" id in ("
> conjunction="," close=")" >
>     #ids[]#
>    </iterate>
>
>
> 2006/6/15, xianwinwin <xi...@gmail.com>:
> >
> >
> > can anyone provide an exmple of how to use this statement with iBatis?
> >
> >        SELECT name,branch,username
> >        FROM KXAccount
> >        WHERE id IN ('234','655','411','775,'416')
> >
> > the problem is in the IN clause: when I try this:
> >
> >                SELECT name,branch,username
> >                FROM KXAccount
> >                WHERE id IN (#ids#)
> >
> > I try this and while popuplating the #ids# with a string of:
> > '234','655','411','775,'416'
> > the result applies only to the first item (234).
> >
> > does anyone know any exmple of IN which iterate through the object?
> > thanks
> >
> >
> > --
> > View this message in context: http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4874196
> >
> > Sent from the iBATIS - User - Java forum at Nabble.com<http://nabble.com/>
> > .
> >
> >
>
>
> --
> RenZenggang
> Renzenggang@gmail.com
> Renzenggang@csii.com
> MSN:rzg117@hotmail.com
> Blog: http://rzg.itpub.net
>
>
>  Send instant messages to your online friends
> http://in.messenger.yahoo.com
>
> Stay connected with your friends even when away from PC. Link:
> http://in.mobile.yahoo.com/new/messenger/
>
>  ------------------------------
> Yahoo! India Answers: Share what you know. Learn something new Click here<http://us.rd.yahoo.com/mail/in/mailanswersshare/*http://in.answers.yahoo.com/>
> Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download
> now<http://us.rd.yahoo.com/mail/in/freesms/*http://messenger.yahoo.com/download.php>
>
>

Re: IN (SQL), how to iterate?

Posted by Nathan Maves <Na...@Sun.COM>.
I would not suggest this method.  You would have to worry about sql  
injection and the loss of ibatis typing.  I would use the iterate tag.


Nathan

On Jun 15, 2006, at 10:33 PM, puneet arya wrote:

> hi,
>  SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN (#ids#)
> You can write in xml as
>
>    SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN ($ids$)
>
> and in these id you have to capture as a string . if u didnt get ,  
> you just tell me teh full scenario i will give you the exact solution.
>
>
>  eg sql:
>
>     SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN (#ids#)
>
>  you can write as this:
>
>
>     SELECT name,branch,username
>                FROM KXAccount
>    <iterate prepend="where" property="ids"open=" id in ("  
> conjunction="," close=")" >
>     #ids[]#
>    </iterate>
>
>
> 2006/6/15, xianwinwin <xi...@gmail.com>:
>
> can anyone provide an exmple of how to use this statement with iBatis?
>
>        SELECT name,branch,username
>        FROM KXAccount
>        WHERE id IN ('234','655','411','775,'416')
>
> the problem is in the IN clause: when I try this:
>
>                SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN (#ids#)
>
> I try this and while popuplating the #ids# with a string of:
> '234','655','411','775,'416'
> the result applies only to the first item (234).
>
> does anyone know any exmple of IN which iterate through the object?
> thanks
>
>
> --
> View this message in context: http://www.nabble.com/IN-%28SQL%29%2C- 
> how-to-iterate--t1789058.html#a4874196
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>
>
>
> -- 
> RenZenggang
> Renzenggang@gmail.com
> Renzenggang@csii.com
> MSN:rzg117@hotmail.com
> Blog: http://rzg.itpub.net
>
> Send instant messages to your online friends http:// 
> in.messenger.yahoo.com
>
> Stay connected with your friends even when away from PC. Link:  
> http://in.mobile.yahoo.com/new/messenger/
>
>
> Yahoo! India Answers: Share what you know. Learn something new  
> Click here
> Send free SMS to your Friends on Mobile from your Yahoo! Messenger  
> Download now


Re: IN (SQL), how to iterate?

Posted by puneet arya <pu...@yahoo.co.in>.
hi,
   SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)
You can write in xml as 
   
     SELECT name,branch,username
               FROM KXAccount
               WHERE id IN ($ids$)
   
  and in these id you have to capture as a string . if u didnt get , you just tell me teh full scenario i will give you the exact solution.



     eg sql: 
     
      SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)

 you can write as this:
   
   
      SELECT name,branch,username
               FROM KXAccount
     <iterate prepend="where" property="ids"open=" id in (" conjunction="," close=")" >
    #ids[]#
   </iterate>

 
  2006/6/15, xianwinwin <xi...@gmail.com>:   
can anyone provide an exmple of how to use this statement with iBatis?

       SELECT name,branch,username 
       FROM KXAccount
       WHERE id IN ('234','655','411','775,'416')

the problem is in the IN clause: when I try this:

               SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)

I try this and while popuplating the #ids# with a string of:
'234','655','411','775,'416'
the result applies only to the first item (234).

does anyone know any exmple of IN which iterate through the object? 
thanks


--
View this message in context: http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4874196 
Sent from the iBATIS - User - Java forum at Nabble.com.





-- 
RenZenggang
Renzenggang@gmail.com 
Renzenggang@csii.com
MSN:rzg117@hotmail.com
Blog: http://rzg.itpub.net


 Send instant messages to your online friends http://in.messenger.yahoo.com 

 Stay connected with your friends even when away from PC.  Link: http://in.mobile.yahoo.com/new/messenger/  
 				
---------------------------------
  Yahoo! India Answers: Share what you know. Learn something new Click here
 Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download now

Re: IN (SQL), how to iterate?

Posted by RZG <re...@gmail.com>.
 eg sql:

    SELECT name,branch,username
               FROM KXAccount
               WHERE id IN (#ids#)

 you can write as this:


    SELECT name,branch,username
               FROM KXAccount
   <iterate prepend="where" property="ids"open=" id in ("
conjunction="," close=")" >
    #ids[]#
   </iterate>


2006/6/15, xianwinwin <xi...@gmail.com>:
>
>
> can anyone provide an exmple of how to use this statement with iBatis?
>
>        SELECT name,branch,username
>        FROM KXAccount
>        WHERE id IN ('234','655','411','775,'416')
>
> the problem is in the IN clause: when I try this:
>
>                SELECT name,branch,username
>                FROM KXAccount
>                WHERE id IN (#ids#)
>
> I try this and while popuplating the #ids# with a string of:
> '234','655','411','775,'416'
> the result applies only to the first item (234).
>
> does anyone know any exmple of IN which iterate through the object?
> thanks
>
>
> --
> View this message in context:
> http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4874196
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>


-- 
RenZenggang
Renzenggang@gmail.com
Renzenggang@csii.com
MSN:rzg117@hotmail.com
Blog: http://rzg.itpub.net

Re: IN (SQL), how to iterate?

Posted by Brandon Goodin <br...@gmail.com>.
If you are using SQL Maps only... then read the docs on SQL Maps.

If you are using DAO and SQL Maps... then read the documents on SQL Maps and
DAO

If you are using DAO only... then read the DAO documentation.

I hope that helps,

Brandon Goodin

On 6/14/06, xianwinwin <xi...@gmail.com> wrote:
>
>
> I looked at the tutorial none has the word iteration.
> could you point to which one i should look at?
>
>     *  Latest OpenOffice Documents in Subversion
>
>     * English PDF
>           o SQL Maps for Java, Developer Guide
>           o SQL Maps for Java, Tutorial
>           o DAO for Java, Developer Guide
>
> thanks
> --
> View this message in context:
> http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4875417
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>

Re: IN (SQL), how to iterate?

Posted by Jeff Butler <je...@gmail.com>.
The SQL Maps for Java, Developer guide shows the usage of the <iterate> tag.

If you look at the documents in SubVersion, the one you want is
iBATIS-SqlMaps-2.pdf

Jeff Butler


On 6/14/06, xianwinwin <xi...@gmail.com> wrote:
>
>
> I looked at the tutorial none has the word iteration.
> could you point to which one i should look at?
>
>    *  Latest OpenOffice Documents in Subversion
>
>    * English PDF
>          o SQL Maps for Java, Developer Guide
>          o SQL Maps for Java, Tutorial
>          o DAO for Java, Developer Guide
>
> thanks
> --
> View this message in context:
> http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4875417
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>

Re: IN (SQL), how to iterate?

Posted by xianwinwin <xi...@gmail.com>.
I looked at the tutorial none has the word iteration.
could you point to which one i should look at?

    *  Latest OpenOffice Documents in Subversion

    * English PDF
          o SQL Maps for Java, Developer Guide
          o SQL Maps for Java, Tutorial
          o DAO for Java, Developer Guide

thanks
--
View this message in context: http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4875417
Sent from the iBATIS - User - Java forum at Nabble.com.


Re: IN (SQL), how to iterate?

Posted by Diran Ayandele <Ad...@Sun.COM>.
Hmmm, try the documentation it will be a short search for you and worth 
your time to read them over.
- look for the iterate tags:

Or for java -> http://ibatis.apache.org/javadownloads.html



xianwinwin wrote:

>can anyone provide an exmple of how to use this statement with iBatis?
>
>    	SELECT name,branch,username 
>        FROM KXAccount
>    	WHERE id IN ('234','655','411','775,'416')
>
>the problem is in the IN clause: when I try this:
>
>    	    	SELECT name,branch,username 
>                FROM KXAccount
>    	        WHERE id IN (#ids#)
>
>I try this and while popuplating the #ids# with a string of:
>'234','655','411','775,'416' 
>the result applies only to the first item (234).
>
>does anyone know any exmple of IN which iterate through the object?
>thanks
>
>
>--
>View this message in context: http://www.nabble.com/IN-%28SQL%29%2C-how-to-iterate--t1789058.html#a4874196
>Sent from the iBATIS - User - Java forum at Nabble.com.
>
>  
>