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 mukhi <vk...@gmail.com> on 2010/04/11 21:41:53 UTC

how to pass two different types of values to query in IBATIS

I am using Spring with Ibatis. I want to pass a sting value and list to a
query. How I can do that. 

My query is as follows
INSERT INTO  
                T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )

                    SELECT  #entryRefno#,CHOICE_REFNO,
                     FROM T_CHOICE
                     WHERE CHOICE_REFNO IN ( 90,89,93,45,67)



in the above query i need to pass two types of parameters. 
1. Sting 
2.list of values in where clause.

How can i do it?


What kind of parameter I can pass to call the query. while making call 

getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
here?);
-- 
View this message in context: http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28211187.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by Nate Weiss <na...@twintechs.com>.
On 4/12/2010 10:24 AM, mukhi wrote:
>
> Thanks, but the parameter 'entryrefno' is of numeric type in my table. How
> can i pass two different types of values to Map  at the same time?
> Please reply me. I am struck at this point.

If you added that numeric value to your map before you passed it in, 
like I typed in my little example, then you would be able to refer to 
the value with the name "entryRefno" inside your query. You can use that 
name because that's the name after the dot here:

 >> params.entryRefno= myEntryRefno;

Not sure what version of iBatis you are using, but in iBatis 3 which is 
what I am most familar with, you would do something like:

SELECT * FROM MyTable
WHERE entryRefno = #{entryRefno, jdbcType=INTEGER}
AND ...


>> Hi mukhi--
>>
>> I'm pretty new to this list, but I believe the general solution is to
>> make a HashMap and pass that in:
>>
>> Map params = new HashMap();
>> params.entryRefno= myEntryRefno;
>> params.someList = someList;
>> getSqlMapClientTemplate().insert("insertChoice", params);
>>
>> In iBatis 3 you also have the option of creating a mapper interface
>> class which allows you to pass in multiple params without a map.
>>
>>
>> On 4/11/2010 3:41 PM, mukhi wrote:
>>>
>>> I am using Spring with Ibatis. I want to pass a sting value and list to a
>>> query. How I can do that.
>>>
>>> My query is as follows
>>> INSERT INTO
>>>                   T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>>
>>>                       SELECT  #entryRefno#,CHOICE_REFNO,
>>>                        FROM T_CHOICE
>>>                        WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>>
>>>
>>>
>>> in the above query i need to pass two types of parameters.
>>> 1. Sting
>>> 2.list of values in where clause.
>>>
>>> How can i do it?
>>>
>>>
>>> What kind of parameter I can pass to call the query. while making call
>>>
>>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>>> here?);
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by François Schiettecatte <fs...@gmail.com>.
There you go, much cleaner, thanks for correcting me, I had not used that particular functionality before.

François

On Apr 12, 2010, at 11:00 AM, Martin Ellis wrote:

> 2010/4/12 François Schiettecatte <fs...@gmail.com>:
>> I think Mukhi is trying to pass a string and an array of numbers, the string being the entryRefno and the list of nunbers to be added to the IN() clause of the SELECT statement in the example given.
>> 
>> The Map is the way to go, you just need to add the string as shows in the code sample below. The array of numbers is more complicated because I dont think there is way to iterate over an array in the map xml (correct me if I am wrong here). The way I would handle this is to turn the array into a comma separated string of numbers and pass that, so in the example below I would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and pass that. Ugly but workable.
> 
> 
> The 'foreach' example in the User Guide shows how to iterate over a
> collection to build an 'IN' clause from a collection.  There's no need
> to build a string.
> 
> Martin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by Ingmar Lötzsch <il...@asci-systemhaus.de>.
I prefer the use of java.sql.Array and a custom TypeHandler and to keep the sql as simple as possible.
Here is an example for Ibatis 2.

Create an IntArrayTypeHandler class and register it in the config.

public class IntArrayTypeHandler
implements TypeHandlerCallback
{
    public void setParameter(ParameterSetter setter, Object parameter)
    throws SQLException
    {
        Collection<Integer> keys = (Collection<Integer>) parameter;
        IntArray intArray = new IntArray(keys);
        setter.setArray(intArray);
    }

    public Object getResult(ResultGetter getter)
    throws SQLException
    {
        Array array = getter.getArray();
        return array;
    }

    public Object valueOf(String string)
    {
        return string;
    }
}

<typeAlias alias="IntArrayTypeHandler"
type="com.asci.common.ibatis.IntArrayTypeHandler" />

I omit the implementation of the IntArray class.

Now you can handle Set<Integer> as a simple parameter. Collection<Integer> would fit too.

<update id="insertSelect" parameterClass="map">
	INSERT ...
	SELECT ...
	WHERE id = ANY (#ids,handler=IntArrayTypeHandler#)
</update>

public int insertSelect(Set<Integer> ids)
{
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("ids", ids);
	int rows = getSqlMapClientTemplate().update("insertSelect", params);
	return rows;
}

Martin Ellis schrieb:
> 2010/4/12 François Schiettecatte <fs...@gmail.com>:
>   
>> I think Mukhi is trying to pass a string and an array of numbers, the string being the entryRefno and the list of nunbers to be added to the IN() clause of the SELECT statement in the example given.
>>
>> The Map is the way to go, you just need to add the string as shows in the code sample below. The array of numbers is more complicated because I dont think there is way to iterate over an array in the map xml (correct me if I am wrong here). The way I would handle this is to turn the array into a comma separated string of numbers and pass that, so in the example below I would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and pass that. Ugly but workable.
>>     
>
>
> The 'foreach' example in the User Guide shows how to iterate over a
> collection to build an 'IN' clause from a collection.  There's no need
> to build a string.
>
> Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by Martin Ellis <el...@gmail.com>.
2010/4/12 François Schiettecatte <fs...@gmail.com>:
> I think Mukhi is trying to pass a string and an array of numbers, the string being the entryRefno and the list of nunbers to be added to the IN() clause of the SELECT statement in the example given.
>
> The Map is the way to go, you just need to add the string as shows in the code sample below. The array of numbers is more complicated because I dont think there is way to iterate over an array in the map xml (correct me if I am wrong here). The way I would handle this is to turn the array into a comma separated string of numbers and pass that, so in the example below I would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and pass that. Ugly but workable.


The 'foreach' example in the User Guide shows how to iterate over a
collection to build an 'IN' clause from a collection.  There's no need
to build a string.

Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by Nathan Maves <na...@gmail.com>.
Sure just name the parameters in your Mapper interface with @Param("foo")



On Tue, Apr 13, 2010 at 12:00 PM, cowwoc <co...@bbs.darktech.org> wrote:
>
>    Is there an equivalent way to do this in iBatis 3 with annotations?
>
> Gili
>
> On 13/04/2010 8:50 AM, mukhi wrote:
>>
>> Your idea of passing a string value would not work out. I tried that....
>> since it is string SQL throws "Invalid number " exception. Do it in the
>> following way.
>>
>>
>>  <dynamic prepend=" WHERE">
>>                          <iterate property="choiceList" open="
>> CHOICE_REFNO
>> IN(" close=")" conjunction=",">#choiceList[]#
>>                      </iterate>
>>                      </dynamic>
>>
>>
>>
>> Above statement is equal to " WHERE CHOICE_REFNO IN( 90,89,93,45,67 )"
>>
>> This would work fine
>>
>>
>> François Schiettecatte wrote:
>>
>>>
>>> I think Mukhi is trying to pass a string and an array of numbers, the
>>> string being the entryRefno and the list of nunbers to be added to the
>>> IN() clause of the SELECT statement in the example given.
>>>
>>> The Map is the way to go, you just need to add the string as shows in the
>>> code sample below. The array of numbers is more complicated because I
>>> dont
>>> think there is way to iterate over an array in the map xml (correct me if
>>> I am wrong here). The way I would handle this is to turn the array into a
>>> comma separated string of numbers and pass that, so in the example below
>>> I
>>> would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and
>>> pass that. Ugly but workable.
>>>
>>> Did I understand the question correctly?
>>>
>>> Cheers
>>>
>>> François
>>>
>>>
>>> On Apr 12, 2010, at 10:41 AM, Nathan Maves wrote:
>>>
>>>
>>>>
>>>> I am not sure you are grasping the concept here.
>>>>
>>>> Both IB2 and IB3 can take any type of java.util.Map implementation as
>>>> a parameter.
>>>>
>>>> Map<String, Object>  parameters = new HashMap<String, Object>();
>>>> parameters.put("someNumber", Integer.valueOf(123));
>>>> parameters.put("someString", "hello");
>>>>
>>>> Now use that parameter as the single parameter to any ibatis sqlmap
>>>> client.
>>>>
>>>> In IB3 you can use multiple named parameters but the above will still
>>>> work.
>>>>
>>>> I would really suggest reading the developers guide.  This is all
>>>> covered in a very short pdf.
>>>>
>>>> Nathan
>>>>
>>>> On Mon, Apr 12, 2010 at 8:24 AM, mukhi<vk...@gmail.com>
>>>>  wrote:
>>>>
>>>>>
>>>>> Thanks, but the parameter 'entryrefno' is of numeric type in my table.
>>>>> How
>>>>> can i pass two different types of values to Map  at the same time?
>>>>> Please reply me. I am struck at this point.
>>>>>
>>>>>
>>>>>
>>>>> Nate Weiss wrote:
>>>>>
>>>>>>
>>>>>> Hi mukhi--
>>>>>>
>>>>>> I'm pretty new to this list, but I believe the general solution is to
>>>>>> make a HashMap and pass that in:
>>>>>>
>>>>>> Map params = new HashMap();
>>>>>> params.entryRefno= myEntryRefno;
>>>>>> params.someList = someList;
>>>>>> getSqlMapClientTemplate().insert("insertChoice", params);
>>>>>>
>>>>>> In iBatis 3 you also have the option of creating a mapper interface
>>>>>> class which allows you to pass in multiple params without a map.
>>>>>>
>>>>>>
>>>>>> On 4/11/2010 3:41 PM, mukhi wrote:
>>>>>>
>>>>>>>
>>>>>>> I am using Spring with Ibatis. I want to pass a sting value and list
>>>>>>> to a
>>>>>>> query. How I can do that.
>>>>>>>
>>>>>>> My query is as follows
>>>>>>> INSERT INTO
>>>>>>>                  T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>>>>>>
>>>>>>>                      SELECT  #entryRefno#,CHOICE_REFNO,
>>>>>>>                       FROM T_CHOICE
>>>>>>>                       WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> in the above query i need to pass two types of parameters.
>>>>>>> 1. Sting
>>>>>>> 2.list of values in where clause.
>>>>>>>
>>>>>>> How can i do it?
>>>>>>>
>>>>>>>
>>>>>>> What kind of parameter I can pass to call the query. while making
>>>>>>> call
>>>>>>>
>>>>>>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>>>>>>> here?);
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>>
>>>>> http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28218461.html
>>>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>>
>>>
>>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by cowwoc <co...@bbs.darktech.org>.
     Is there an equivalent way to do this in iBatis 3 with annotations?

Gili

On 13/04/2010 8:50 AM, mukhi wrote:
> Your idea of passing a string value would not work out. I tried that....
> since it is string SQL throws "Invalid number " exception. Do it in the
> following way.
>
>
>   <dynamic prepend=" WHERE">
>                           <iterate property="choiceList" open=" CHOICE_REFNO
> IN(" close=")" conjunction=",">#choiceList[]#
>                       </iterate>
>                       </dynamic>
>
>
>
> Above statement is equal to " WHERE CHOICE_REFNO IN( 90,89,93,45,67 )"
>
> This would work fine
>
>
> François Schiettecatte wrote:
>    
>> I think Mukhi is trying to pass a string and an array of numbers, the
>> string being the entryRefno and the list of nunbers to be added to the
>> IN() clause of the SELECT statement in the example given.
>>
>> The Map is the way to go, you just need to add the string as shows in the
>> code sample below. The array of numbers is more complicated because I dont
>> think there is way to iterate over an array in the map xml (correct me if
>> I am wrong here). The way I would handle this is to turn the array into a
>> comma separated string of numbers and pass that, so in the example below I
>> would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and
>> pass that. Ugly but workable.
>>
>> Did I understand the question correctly?
>>
>> Cheers
>>
>> François
>>
>>
>> On Apr 12, 2010, at 10:41 AM, Nathan Maves wrote:
>>
>>      
>>> I am not sure you are grasping the concept here.
>>>
>>> Both IB2 and IB3 can take any type of java.util.Map implementation as
>>> a parameter.
>>>
>>> Map<String, Object>  parameters = new HashMap<String, Object>();
>>> parameters.put("someNumber", Integer.valueOf(123));
>>> parameters.put("someString", "hello");
>>>
>>> Now use that parameter as the single parameter to any ibatis sqlmap
>>> client.
>>>
>>> In IB3 you can use multiple named parameters but the above will still
>>> work.
>>>
>>> I would really suggest reading the developers guide.  This is all
>>> covered in a very short pdf.
>>>
>>> Nathan
>>>
>>> On Mon, Apr 12, 2010 at 8:24 AM, mukhi<vk...@gmail.com>  wrote:
>>>        
>>>> Thanks, but the parameter 'entryrefno' is of numeric type in my table.
>>>> How
>>>> can i pass two different types of values to Map  at the same time?
>>>> Please reply me. I am struck at this point.
>>>>
>>>>
>>>>
>>>> Nate Weiss wrote:
>>>>          
>>>>> Hi mukhi--
>>>>>
>>>>> I'm pretty new to this list, but I believe the general solution is to
>>>>> make a HashMap and pass that in:
>>>>>
>>>>> Map params = new HashMap();
>>>>> params.entryRefno= myEntryRefno;
>>>>> params.someList = someList;
>>>>> getSqlMapClientTemplate().insert("insertChoice", params);
>>>>>
>>>>> In iBatis 3 you also have the option of creating a mapper interface
>>>>> class which allows you to pass in multiple params without a map.
>>>>>
>>>>>
>>>>> On 4/11/2010 3:41 PM, mukhi wrote:
>>>>>            
>>>>>> I am using Spring with Ibatis. I want to pass a sting value and list
>>>>>> to a
>>>>>> query. How I can do that.
>>>>>>
>>>>>> My query is as follows
>>>>>> INSERT INTO
>>>>>>                   T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>>>>>
>>>>>>                       SELECT  #entryRefno#,CHOICE_REFNO,
>>>>>>                        FROM T_CHOICE
>>>>>>                        WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>>>>>
>>>>>>
>>>>>>
>>>>>> in the above query i need to pass two types of parameters.
>>>>>> 1. Sting
>>>>>> 2.list of values in where clause.
>>>>>>
>>>>>> How can i do it?
>>>>>>
>>>>>>
>>>>>> What kind of parameter I can pass to call the query. while making call
>>>>>>
>>>>>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>>>>>> here?);
>>>>>>              
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>
>>>>>
>>>>>
>>>>>            
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28218461.html
>>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>
>>>>
>>>>          
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>>        
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>>
>>      
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by mukhi <vk...@gmail.com>.
Your idea of passing a string value would not work out. I tried that....
since it is string SQL throws "Invalid number " exception. Do it in the
following way.


 <dynamic prepend=" WHERE">
                         <iterate property="choiceList" open=" CHOICE_REFNO
IN(" close=")" conjunction=",">#choiceList[]#
                     </iterate>
                     </dynamic>



Above statement is equal to " WHERE CHOICE_REFNO IN( 90,89,93,45,67 )"

This would work fine


François Schiettecatte wrote:
> 
> I think Mukhi is trying to pass a string and an array of numbers, the
> string being the entryRefno and the list of nunbers to be added to the
> IN() clause of the SELECT statement in the example given.
> 
> The Map is the way to go, you just need to add the string as shows in the
> code sample below. The array of numbers is more complicated because I dont
> think there is way to iterate over an array in the map xml (correct me if
> I am wrong here). The way I would handle this is to turn the array into a
> comma separated string of numbers and pass that, so in the example below I
> would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and
> pass that. Ugly but workable.
> 
> Did I understand the question correctly?
> 
> Cheers
> 
> François
> 
> 
> On Apr 12, 2010, at 10:41 AM, Nathan Maves wrote:
> 
>> I am not sure you are grasping the concept here.
>> 
>> Both IB2 and IB3 can take any type of java.util.Map implementation as
>> a parameter.
>> 
>> Map<String, Object> parameters = new HashMap<String, Object>();
>> parameters.put("someNumber", Integer.valueOf(123));
>> parameters.put("someString", "hello");
>> 
>> Now use that parameter as the single parameter to any ibatis sqlmap
>> client.
>> 
>> In IB3 you can use multiple named parameters but the above will still
>> work.
>> 
>> I would really suggest reading the developers guide.  This is all
>> covered in a very short pdf.
>> 
>> Nathan
>> 
>> On Mon, Apr 12, 2010 at 8:24 AM, mukhi <vk...@gmail.com> wrote:
>>> 
>>> Thanks, but the parameter 'entryrefno' is of numeric type in my table.
>>> How
>>> can i pass two different types of values to Map  at the same time?
>>> Please reply me. I am struck at this point.
>>> 
>>> 
>>> 
>>> Nate Weiss wrote:
>>>> 
>>>> Hi mukhi--
>>>> 
>>>> I'm pretty new to this list, but I believe the general solution is to
>>>> make a HashMap and pass that in:
>>>> 
>>>> Map params = new HashMap();
>>>> params.entryRefno= myEntryRefno;
>>>> params.someList = someList;
>>>> getSqlMapClientTemplate().insert("insertChoice", params);
>>>> 
>>>> In iBatis 3 you also have the option of creating a mapper interface
>>>> class which allows you to pass in multiple params without a map.
>>>> 
>>>> 
>>>> On 4/11/2010 3:41 PM, mukhi wrote:
>>>>> 
>>>>> I am using Spring with Ibatis. I want to pass a sting value and list
>>>>> to a
>>>>> query. How I can do that.
>>>>> 
>>>>> My query is as follows
>>>>> INSERT INTO
>>>>>                  T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>>>> 
>>>>>                      SELECT  #entryRefno#,CHOICE_REFNO,
>>>>>                       FROM T_CHOICE
>>>>>                       WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>>>> 
>>>>> 
>>>>> 
>>>>> in the above query i need to pass two types of parameters.
>>>>> 1. Sting
>>>>> 2.list of values in where clause.
>>>>> 
>>>>> How can i do it?
>>>>> 
>>>>> 
>>>>> What kind of parameter I can pass to call the query. while making call
>>>>> 
>>>>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>>>>> here?);
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>> 
>>>> 
>>>> 
>>> 
>>> --
>>> View this message in context:
>>> http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28218461.html
>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>> 
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28229528.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by François Schiettecatte <fs...@gmail.com>.
I think Mukhi is trying to pass a string and an array of numbers, the string being the entryRefno and the list of nunbers to be added to the IN() clause of the SELECT statement in the example given.

The Map is the way to go, you just need to add the string as shows in the code sample below. The array of numbers is more complicated because I dont think there is way to iterate over an array in the map xml (correct me if I am wrong here). The way I would handle this is to turn the array into a comma separated string of numbers and pass that, so in the example below I would turn the array (90,89,93,45,67) into a string "90,89,93,45,67" and pass that. Ugly but workable.

Did I understand the question correctly?

Cheers

François


On Apr 12, 2010, at 10:41 AM, Nathan Maves wrote:

> I am not sure you are grasping the concept here.
> 
> Both IB2 and IB3 can take any type of java.util.Map implementation as
> a parameter.
> 
> Map<String, Object> parameters = new HashMap<String, Object>();
> parameters.put("someNumber", Integer.valueOf(123));
> parameters.put("someString", "hello");
> 
> Now use that parameter as the single parameter to any ibatis sqlmap client.
> 
> In IB3 you can use multiple named parameters but the above will still work.
> 
> I would really suggest reading the developers guide.  This is all
> covered in a very short pdf.
> 
> Nathan
> 
> On Mon, Apr 12, 2010 at 8:24 AM, mukhi <vk...@gmail.com> wrote:
>> 
>> Thanks, but the parameter 'entryrefno' is of numeric type in my table. How
>> can i pass two different types of values to Map  at the same time?
>> Please reply me. I am struck at this point.
>> 
>> 
>> 
>> Nate Weiss wrote:
>>> 
>>> Hi mukhi--
>>> 
>>> I'm pretty new to this list, but I believe the general solution is to
>>> make a HashMap and pass that in:
>>> 
>>> Map params = new HashMap();
>>> params.entryRefno= myEntryRefno;
>>> params.someList = someList;
>>> getSqlMapClientTemplate().insert("insertChoice", params);
>>> 
>>> In iBatis 3 you also have the option of creating a mapper interface
>>> class which allows you to pass in multiple params without a map.
>>> 
>>> 
>>> On 4/11/2010 3:41 PM, mukhi wrote:
>>>> 
>>>> I am using Spring with Ibatis. I want to pass a sting value and list to a
>>>> query. How I can do that.
>>>> 
>>>> My query is as follows
>>>> INSERT INTO
>>>>                  T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>>> 
>>>>                      SELECT  #entryRefno#,CHOICE_REFNO,
>>>>                       FROM T_CHOICE
>>>>                       WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>>> 
>>>> 
>>>> 
>>>> in the above query i need to pass two types of parameters.
>>>> 1. Sting
>>>> 2.list of values in where clause.
>>>> 
>>>> How can i do it?
>>>> 
>>>> 
>>>> What kind of parameter I can pass to call the query. while making call
>>>> 
>>>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>>>> here?);
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>> 
>>> 
>>> 
>> 
>> --
>> View this message in context: http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28218461.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by Nathan Maves <na...@gmail.com>.
I am not sure you are grasping the concept here.

Both IB2 and IB3 can take any type of java.util.Map implementation as
a parameter.

Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("someNumber", Integer.valueOf(123));
parameters.put("someString", "hello");

Now use that parameter as the single parameter to any ibatis sqlmap client.

In IB3 you can use multiple named parameters but the above will still work.

I would really suggest reading the developers guide.  This is all
covered in a very short pdf.

Nathan

On Mon, Apr 12, 2010 at 8:24 AM, mukhi <vk...@gmail.com> wrote:
>
> Thanks, but the parameter 'entryrefno' is of numeric type in my table. How
> can i pass two different types of values to Map  at the same time?
> Please reply me. I am struck at this point.
>
>
>
> Nate Weiss wrote:
>>
>> Hi mukhi--
>>
>> I'm pretty new to this list, but I believe the general solution is to
>> make a HashMap and pass that in:
>>
>> Map params = new HashMap();
>> params.entryRefno= myEntryRefno;
>> params.someList = someList;
>> getSqlMapClientTemplate().insert("insertChoice", params);
>>
>> In iBatis 3 you also have the option of creating a mapper interface
>> class which allows you to pass in multiple params without a map.
>>
>>
>> On 4/11/2010 3:41 PM, mukhi wrote:
>>>
>>> I am using Spring with Ibatis. I want to pass a sting value and list to a
>>> query. How I can do that.
>>>
>>> My query is as follows
>>> INSERT INTO
>>>                  T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>>
>>>                      SELECT  #entryRefno#,CHOICE_REFNO,
>>>                       FROM T_CHOICE
>>>                       WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>>
>>>
>>>
>>> in the above query i need to pass two types of parameters.
>>> 1. Sting
>>> 2.list of values in where clause.
>>>
>>> How can i do it?
>>>
>>>
>>> What kind of parameter I can pass to call the query. while making call
>>>
>>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>>> here?);
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28218461.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by mukhi <vk...@gmail.com>.
Thanks, but the parameter 'entryrefno' is of numeric type in my table. How
can i pass two different types of values to Map  at the same time?
Please reply me. I am struck at this point.



Nate Weiss wrote:
> 
> Hi mukhi--
> 
> I'm pretty new to this list, but I believe the general solution is to 
> make a HashMap and pass that in:
> 
> Map params = new HashMap();
> params.entryRefno= myEntryRefno;
> params.someList = someList;
> getSqlMapClientTemplate().insert("insertChoice", params);
> 
> In iBatis 3 you also have the option of creating a mapper interface 
> class which allows you to pass in multiple params without a map.
> 
> 
> On 4/11/2010 3:41 PM, mukhi wrote:
>>
>> I am using Spring with Ibatis. I want to pass a sting value and list to a
>> query. How I can do that.
>>
>> My query is as follows
>> INSERT INTO
>>                  T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>>
>>                      SELECT  #entryRefno#,CHOICE_REFNO,
>>                       FROM T_CHOICE
>>                       WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>>
>>
>>
>> in the above query i need to pass two types of parameters.
>> 1. Sting
>> 2.list of values in where clause.
>>
>> How can i do it?
>>
>>
>> What kind of parameter I can pass to call the query. while making call
>>
>> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
>> here?);
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/how-to-pass-two-different-types-of-values-to-query-in-IBATIS-tp28211187p28218461.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: how to pass two different types of values to query in IBATIS

Posted by Nate Weiss <na...@twintechs.com>.
Hi mukhi--

I'm pretty new to this list, but I believe the general solution is to 
make a HashMap and pass that in:

Map params = new HashMap();
params.entryRefno= myEntryRefno;
params.someList = someList;
getSqlMapClientTemplate().insert("insertChoice", params);

In iBatis 3 you also have the option of creating a mapper interface 
class which allows you to pass in multiple params without a map.


On 4/11/2010 3:41 PM, mukhi wrote:
>
> I am using Spring with Ibatis. I want to pass a sting value and list to a
> query. How I can do that.
>
> My query is as follows
> INSERT INTO
>                  T_ENTRY_ANSWER_ASSOC( ENTRY_REFNO,   CHOICE_REFNO  )
>
>                      SELECT  #entryRefno#,CHOICE_REFNO,
>                       FROM T_CHOICE
>                       WHERE CHOICE_REFNO IN ( 90,89,93,45,67)
>
>
>
> in the above query i need to pass two types of parameters.
> 1. Sting
> 2.list of values in where clause.
>
> How can i do it?
>
>
> What kind of parameter I can pass to call the query. while making call
>
> getSqlMapClientTemplate().insert("insertChoice",  What parameter goes
> here?);


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org