数据转换无效:参数实例50.0 / 100对于请求的转换无效。 ERRORCODE = -4461,SQLSTATE = 42815 [英] Invalid data conversion: Parameter instance 50.0/100 is invalid for the requested conversion. ERRORCODE=-4461, SQLSTATE=42815
问题描述
String expression = CHEMICAL_REORDERPOINT + "*" + searchRequest.getReorderPercentage() + "/100)";
之前:
String expression = CHEMICAL_REORDERPOINT + "*" + searchRequest.getReorderPercentage() + "/100)";
searchRequest.getReorderPercentage()
浏览器提交后的值。
让$ searchRequest.getReorderPercentage()= 50
searchRequest.getReorderPercentage()
comes dynamically from browser after submit value.
Lets take value for searchRequest.getReorderPercentage() = 50
so String expression = CHEMICAL_REORDERPOINT*50/100;
这是在一个准备好的语句 JDBC
在我的应用程序中,所以要保持准备语句规则我以下方式使用:
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:
之后:
String expression = CHEMICAL_REORDERPOINT + "*?)"
String str = searchRequest.getReorderPercentage() + "/100";
params.add(str)
这里params是一个列表,从中将参数迭代并将它放在准备语句的postion参数中执行。
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.
但是现在可以像
获取异常无效的数据转换:参数实例50.0 / 100对于请求的转换无效。 ERRORCODE = -4461,SQLSTATE = 42815
任何人都可以帮助我。谢谢
Pls can any one help me out. Thanks
推荐答案
您的参数化查询字符串应该看起来像 CHEMICAL_REORDERPOINT *(?/ 100)
,您应该使用setDouble()或setFloat()设置百分比值,而不是String。现在你试图告诉DB2将字符串乘以任何一个字符串,这没有什么意义。
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.
这篇关于数据转换无效:参数实例50.0 / 100对于请求的转换无效。 ERRORCODE = -4461,SQLSTATE = 42815的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!