无效的数据转换:参数实例 50.0/100 对请求的转换无效.错误代码=-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是一个列表,参数将被迭代并在执行时将放在prepare语句的位置参数中.
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
请任何人帮助我.谢谢
推荐答案
你的参数化查询字符串应该看起来像whatever is in CHEMICAL_REORDERPOINT * (?/100)
",你应该设置百分比使用 setDouble() 或 setFloat() 的值,而不是字符串.现在您正试图告诉 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 对请求的转换无效.错误代码=-4461,SQLSTATE=42815的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!