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 sonusgr <so...@gmail.com> on 2006/10/10 18:09:28 UTC

Invalid Number

Hi guys,

I am trying to pass a string of numbers to the my sql statement 
but  I am getting SQLException invalid number

The funny thing is that this occurs only when I am passing more than one
number, meaning if that string I am passing
having more than one number. 

so in DAO we ve got :
searchVO.setCostComponentIdArrayAsString("1234,456,588");
	    		flights = this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);


and in sqlMap:
AND COMPONENT_MOVEMENT_TYPE_ID in (#costComponentIdArrayAsString#)

that throws the SQLException

---------

But if I do searchVO.setCostComponentIdArrayAsString("1234");
works fine...

What am I doing wrong here?
could it be a backend error?

thanks guys
-- 
View this message in context: http://www.nabble.com/Invalid-Number-tf2417727.html#a6739736
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Invalid Number

Posted by sonusgr <so...@gmail.com>.
OK got it

Thank you all guys for your help

Guido García Bernardo-2 wrote:
> 
> You should use the $xxxx$ sintax as Larry describes.
> 
> searchVO.setCostComponentIdArrayAsString("\"1234\",\"456\",\"588\"");
> flights = this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);
> 
> and in sqlMap:
>     AND COMPONENT_MOVEMENT_TYPE_ID in ($costComponentIdArrayAsString$)
> 
> On the other hand, maybe your database uses the SINGLE QUOTE:
>     searchVO.setCostComponentIdArrayAsString("'1234','456','588'");
> 
> As Larry said, I'd reccomend you to pass in an array or list instead of 
> a String.
> 
> sonusgr escribió:
>> Thanks for your quick reply. I tried setting the string as
>> searchVO.setCostComponentIdArrayAsString("\"1234\",\"456\",\"588\"");
>> so that it would get into the sqlmap as  "1234","456","588"
>> but no luck. Still getting invalid number.
>> I also tried hard coding them inside the sqlmap with quotes but still no
>> luck.
>> Did I misunderstood something?
>>
>> Thanks
>>
>> Larry Meadors-2 wrote:
>>   
>>> iBATIS uses prepared statements for this, so the SQL that is being
>>> executed is like this:
>>>
>>> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12,34,56")
>>>
>>> That won't work. you need to make the values like this:
>>>
>>> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12","34","56")
>>>
>>> That means you either use sql injection (err, substitution I mean) like
>>> this:
>>>
>>> ... AND COMPONENT_MOVEMENT_TYPE_ID in ($someValues$)
>>>
>>> ...or you need to pass in an array or list and search the archives for
>>> "dynamic sql" and "iterate". I'd highly reccomend this approach over
>>> the $other$.
>>>
>>> Larry
>>>
>>>
>>> On 10/10/06, sonusgr <so...@gmail.com> wrote:
>>>     
>>>> Hi guys,
>>>>
>>>> I am trying to pass a string of numbers to the my sql statement
>>>> but  I am getting SQLException invalid number
>>>>
>>>> The funny thing is that this occurs only when I am passing more than
>>>> one
>>>> number, meaning if that string I am passing
>>>> having more than one number.
>>>>
>>>> so in DAO we ve got :
>>>> searchVO.setCostComponentIdArrayAsString("1234,456,588");
>>>>                         flights =
>>>> this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);
>>>>
>>>>
>>>> and in sqlMap:
>>>> AND COMPONENT_MOVEMENT_TYPE_ID in (#costComponentIdArrayAsString#)
>>>>
>>>> that throws the SQLException
>>>>
>>>> ---------
>>>>
>>>> But if I do searchVO.setCostComponentIdArrayAsString("1234");
>>>> works fine...
>>>>
>>>> What am I doing wrong here?
>>>> could it be a backend error?
>>>>
>>>> thanks guys
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Invalid-Number-tf2417727.html#a6739736
>>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>>>
>>>>
>>>>       
>>>     
>>
>>   
> 
> 
> -- 
> Guido García Bernardo
> 
> Tfn. +34 983 54 89 08
> ITDEUSTO - Valladolid
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Invalid-Number-tf2417727.html#a6772818
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Invalid Number

Posted by Guido García Bernardo <gg...@tid.es>.
You should use the $xxxx$ sintax as Larry describes.

searchVO.setCostComponentIdArrayAsString("\"1234\",\"456\",\"588\"");
flights = this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);

and in sqlMap:
    AND COMPONENT_MOVEMENT_TYPE_ID in ($costComponentIdArrayAsString$)

On the other hand, maybe your database uses the SINGLE QUOTE:
    searchVO.setCostComponentIdArrayAsString("'1234','456','588'");

As Larry said, I'd reccomend you to pass in an array or list instead of 
a String.

sonusgr escribió:
> Thanks for your quick reply. I tried setting the string as
> searchVO.setCostComponentIdArrayAsString("\"1234\",\"456\",\"588\"");
> so that it would get into the sqlmap as  "1234","456","588"
> but no luck. Still getting invalid number.
> I also tried hard coding them inside the sqlmap with quotes but still no
> luck.
> Did I misunderstood something?
>
> Thanks
>
> Larry Meadors-2 wrote:
>   
>> iBATIS uses prepared statements for this, so the SQL that is being
>> executed is like this:
>>
>> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12,34,56")
>>
>> That won't work. you need to make the values like this:
>>
>> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12","34","56")
>>
>> That means you either use sql injection (err, substitution I mean) like
>> this:
>>
>> ... AND COMPONENT_MOVEMENT_TYPE_ID in ($someValues$)
>>
>> ...or you need to pass in an array or list and search the archives for
>> "dynamic sql" and "iterate". I'd highly reccomend this approach over
>> the $other$.
>>
>> Larry
>>
>>
>> On 10/10/06, sonusgr <so...@gmail.com> wrote:
>>     
>>> Hi guys,
>>>
>>> I am trying to pass a string of numbers to the my sql statement
>>> but  I am getting SQLException invalid number
>>>
>>> The funny thing is that this occurs only when I am passing more than one
>>> number, meaning if that string I am passing
>>> having more than one number.
>>>
>>> so in DAO we ve got :
>>> searchVO.setCostComponentIdArrayAsString("1234,456,588");
>>>                         flights =
>>> this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);
>>>
>>>
>>> and in sqlMap:
>>> AND COMPONENT_MOVEMENT_TYPE_ID in (#costComponentIdArrayAsString#)
>>>
>>> that throws the SQLException
>>>
>>> ---------
>>>
>>> But if I do searchVO.setCostComponentIdArrayAsString("1234");
>>> works fine...
>>>
>>> What am I doing wrong here?
>>> could it be a backend error?
>>>
>>> thanks guys
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Invalid-Number-tf2417727.html#a6739736
>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>>
>>>
>>>       
>>     
>
>   


-- 
Guido García Bernardo

Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid


RE: Invalid Number

Posted by Poitras Christian <Ch...@ircm.qc.ca>.
A better way would be to pass the parameter as a List (or array) of int
and use the iterate tag (see ibatis doc).

Christian

-----Original Message-----
From: sonusgr [mailto:sonusgr@gmail.com] 
Sent: Wednesday, 11 October 2006 08:44
To: user-java@ibatis.apache.org
Subject: Re: Invalid Number


Thanks for your quick reply. I tried setting the string as
searchVO.setCostComponentIdArrayAsString("\"1234\",\"456\",\"588\"");
so that it would get into the sqlmap as  "1234","456","588"
but no luck. Still getting invalid number.
I also tried hard coding them inside the sqlmap with quotes but still no
luck.
Did I misunderstood something?

Thanks

Larry Meadors-2 wrote:
> 
> iBATIS uses prepared statements for this, so the SQL that is being 
> executed is like this:
> 
> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12,34,56")
> 
> That won't work. you need to make the values like this:
> 
> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12","34","56")
> 
> That means you either use sql injection (err, substitution I mean) 
> like
> this:
> 
> ... AND COMPONENT_MOVEMENT_TYPE_ID in ($someValues$)
> 
> ...or you need to pass in an array or list and search the archives for

> "dynamic sql" and "iterate". I'd highly reccomend this approach over 
> the $other$.
> 
> Larry
> 
> 
> On 10/10/06, sonusgr <so...@gmail.com> wrote:
>>
>> Hi guys,
>>
>> I am trying to pass a string of numbers to the my sql statement but  
>> I am getting SQLException invalid number
>>
>> The funny thing is that this occurs only when I am passing more than 
>> one number, meaning if that string I am passing having more than one 
>> number.
>>
>> so in DAO we ve got :
>> searchVO.setCostComponentIdArrayAsString("1234,456,588");
>>                         flights =
>> this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);
>>
>>
>> and in sqlMap:
>> AND COMPONENT_MOVEMENT_TYPE_ID in (#costComponentIdArrayAsString#)
>>
>> that throws the SQLException
>>
>> ---------
>>
>> But if I do searchVO.setCostComponentIdArrayAsString("1234");
>> works fine...
>>
>> What am I doing wrong here?
>> could it be a backend error?
>>
>> thanks guys
>> --
>> View this message in context:
>> http://www.nabble.com/Invalid-Number-tf2417727.html#a6739736
>> Sent from the iBATIS - User - Java mailing list archive at
Nabble.com.
>>
>>
> 
> 

--
View this message in context:
http://www.nabble.com/Invalid-Number-tf2417727.html#a6755642
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.



Re: Invalid Number

Posted by sonusgr <so...@gmail.com>.
Thanks for your quick reply. I tried setting the string as
searchVO.setCostComponentIdArrayAsString("\"1234\",\"456\",\"588\"");
so that it would get into the sqlmap as  "1234","456","588"
but no luck. Still getting invalid number.
I also tried hard coding them inside the sqlmap with quotes but still no
luck.
Did I misunderstood something?

Thanks

Larry Meadors-2 wrote:
> 
> iBATIS uses prepared statements for this, so the SQL that is being
> executed is like this:
> 
> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12,34,56")
> 
> That won't work. you need to make the values like this:
> 
> ... AND COMPONENT_MOVEMENT_TYPE_ID in ("12","34","56")
> 
> That means you either use sql injection (err, substitution I mean) like
> this:
> 
> ... AND COMPONENT_MOVEMENT_TYPE_ID in ($someValues$)
> 
> ...or you need to pass in an array or list and search the archives for
> "dynamic sql" and "iterate". I'd highly reccomend this approach over
> the $other$.
> 
> Larry
> 
> 
> On 10/10/06, sonusgr <so...@gmail.com> wrote:
>>
>> Hi guys,
>>
>> I am trying to pass a string of numbers to the my sql statement
>> but  I am getting SQLException invalid number
>>
>> The funny thing is that this occurs only when I am passing more than one
>> number, meaning if that string I am passing
>> having more than one number.
>>
>> so in DAO we ve got :
>> searchVO.setCostComponentIdArrayAsString("1234,456,588");
>>                         flights =
>> this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);
>>
>>
>> and in sqlMap:
>> AND COMPONENT_MOVEMENT_TYPE_ID in (#costComponentIdArrayAsString#)
>>
>> that throws the SQLException
>>
>> ---------
>>
>> But if I do searchVO.setCostComponentIdArrayAsString("1234");
>> works fine...
>>
>> What am I doing wrong here?
>> could it be a backend error?
>>
>> thanks guys
>> --
>> View this message in context:
>> http://www.nabble.com/Invalid-Number-tf2417727.html#a6739736
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Invalid-Number-tf2417727.html#a6755642
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Invalid Number

Posted by Larry Meadors <lm...@apache.org>.
iBATIS uses prepared statements for this, so the SQL that is being
executed is like this:

... AND COMPONENT_MOVEMENT_TYPE_ID in ("12,34,56")

That won't work. you need to make the values like this:

... AND COMPONENT_MOVEMENT_TYPE_ID in ("12","34","56")

That means you either use sql injection (err, substitution I mean) like this:

... AND COMPONENT_MOVEMENT_TYPE_ID in ($someValues$)

...or you need to pass in an array or list and search the archives for
"dynamic sql" and "iterate". I'd highly reccomend this approach over
the $other$.

Larry


On 10/10/06, sonusgr <so...@gmail.com> wrote:
>
> Hi guys,
>
> I am trying to pass a string of numbers to the my sql statement
> but  I am getting SQLException invalid number
>
> The funny thing is that this occurs only when I am passing more than one
> number, meaning if that string I am passing
> having more than one number.
>
> so in DAO we ve got :
> searchVO.setCostComponentIdArrayAsString("1234,456,588");
>                         flights = this.sqlMap.queryForList("getFlightsbyCriteria", searchVO);
>
>
> and in sqlMap:
> AND COMPONENT_MOVEMENT_TYPE_ID in (#costComponentIdArrayAsString#)
>
> that throws the SQLException
>
> ---------
>
> But if I do searchVO.setCostComponentIdArrayAsString("1234");
> works fine...
>
> What am I doing wrong here?
> could it be a backend error?
>
> thanks guys
> --
> View this message in context: http://www.nabble.com/Invalid-Number-tf2417727.html#a6739736
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>