[英]java.sql.SQLException: 'Infinity' is not a valid numeric or approximate numeric value
I am using a java function which returns a float 我正在使用返回浮点数的Java函数
private float getEventScaledX(float eventX, float resX) {
return (eventX * frameWidth) / resX;
}
While storing it under mysql db it throws exception as 当将其存储在mysql db下时,它抛出异常为
Caused by: java.sql.SQLException: 'Infinity' is not a valid numeric or approximate numeric value
Please suggest a right way to handle it at java side to stop this exception but also to get right expected result. 请提出在Java端处理它的正确方法,以停止此异常,同时也获得正确的预期结果。
The issue here was (as reported by @c0der and @apomene ) resX coming as zero. 这里的问题是(由@ c0der和@apomene报告)resX为零。
JAVA float data type does not throw any arithmetic exception while division by zero operation, rather returns Infinity / NaN as value. JAVA浮点数据类型在除以零运算时不会引发任何算术异常,而是返回Infinity / NaN作为值。 Which MySQL can't store as valid numeric type so the exception.
哪个MySQL不能将其存储为有效的数字类型,所以例外。
Checking for ( resX > 0 ) fixed my issue . 检查(resX> 0)解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.