1
String expression = CHEMICAL_REORDERPOINT + "*" + searchRequest.getReorderPercentage() + "/100)";

Before :

String expression = CHEMICAL_REORDERPOINT + "*" + searchRequest.getReorderPercentage() + "/100)";

searchRequest.getReorderPercentage() comes dynamically from browser after submit value. Lets take value for searchRequest.getReorderPercentage() = 50

so String expression = CHEMICAL_REORDERPOINT*50/100; 

This is getting populated in a prepared statement of JDBC in my application, so to maintain the prepare statement rule i have used in below way:

After :

String expression = CHEMICAL_REORDERPOINT + "*?)"
String str = searchRequest.getReorderPercentage() + "/100";
params.add(str)

here params is a list from which the parameters will be iterated and will be placed in postion parameters of prepare statement while executing it.

But now i m getting exception like Invalid data conversion: Parameter instance 50.0/100 is invalid for the requested conversion. ERRORCODE=-4461, SQLSTATE=42815

Pls can any one help me out. Thanks

jpw
  • 44,361
  • 6
  • 66
  • 86
Ashok
  • 81
  • 1
  • 4
  • 11
  • this isn't SQL. please change tag – Luis LL Jul 30 '13 at 08:06
  • @LuisLL Looks to me like he is constructing an SQL query, but I agree it would have been better if he included the actual SQL query produced – Mark Rotteveel Jul 30 '13 at 08:34
  • 2
    Not an expert on jdbc+db2 but... is it legal to specify a parameter using an expression in stead of a value? Isn't it interpreting the parameter as a string so that the resulting sql is " * '50/100' " leading to a conversion error? – Giacomo Degli Esposti Jul 30 '13 at 09:36

2 Answers2

1

Your parameterized query string should look like "whatever is in CHEMICAL_REORDERPOINT * (? / 100)", and you should set the percentage value using setDouble() or setFloat(), not as a String. Right now you are trying to tell DB2 to multiply whatever by a string, which doesn't make much sense.

mustaccio
  • 18,234
  • 16
  • 48
  • 57
0

If I had to guess I would say it is an auto conversion issue.

You had something like

5 * 50.0 / 100

and it worked.

No you have

50.0 / 100

and it fails.

It seems in the first it converted all operands to integers and in the second it converts them to floating point. But 100 is not a valid floating point constant. So change your new output to

50.0 / 100.0

or

50 / 100
Hogan
  • 69,564
  • 10
  • 76
  • 117