Following is the query which I'm trying to handle in Prepared statement. In which AmountOnHand & ReorderPointAmt is of data type Decimal.
Query 1: SELECT AmountOnHand FROM TableA WHERE AmountOnHand <= (ReorderPointAmt*56.0/100);
Where 56.0 is a dynamic value.
So I updated the query as below
Query 2: SELECT AmountOnHand FROM TableA WHERE AmountOnHand <= (ReorderPointAmt*?);
But when this query is executed I'm getting the following exception:
Arithmetic overflow or other arithmetic exception occurred.. SQLCODE=-802, SQLSTATE=22003, DRIVER=4.15.82.
I'm able to fix this issue by updating the query like below
Query 3: SELECT AmountOnHand FROM TableA WHERE AmountOnHand <= (ReorderPointAmt * CAST(? AS DECIMAL));
But I could not understand what made the Query:2 to end up in exception. I'm using java.sql.PreparedStatement.setObject(index, Object)
to feed the value for Query:2.
I tried by setting Double
& Float
Object in setObject
method. Still facing the issue.
使用任何适当的数据类型,例如java.sql.PreparedStatement.setString(index, "String value")
或setInt()
或setDouble()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.