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

4

2 回答 2

1

您的参数化查询字符串应该看起来像“ whatever is in CHEMICAL_REORDERPOINT * (? / 100)”,并且您应该使用 setDouble() 或 setFloat() 设置百分比值,而不是作为字符串。现在您正试图告诉 DB2 将任何内容乘以一个字符串,这没有多大意义。

于 2013-07-30T12:00:48.457 回答
0

如果我不得不猜测,我会说这是一个自动转换问题。

你有类似的东西

5 * 50.0 / 100

它奏效了。

不,你有

50.0 / 100

它失败了。

似乎第一次它将所有操作数转换为整数,第二次将它们转换为浮点数。但是 100 不是有效的浮点常数。因此,将您的新输出更改为

50.0 / 100.0

或者

50 / 100
于 2013-07-30T08:40:07.340 回答