简体   繁体   English

java.sql.SQLException:'Infinity'不是有效的数字或近似数字值

[英]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.

相关问题 java.sql.SQLException:数值溢出 - java.sql.SQLException: Numeric Overflow 获取SQL异常“NaN”不是有效的数字或近似数值 - Getting an SQL Exception 'NaN' is not a valid numeric or approximate numeric value java JDBC:引起:java.sql.SQLException:数字溢出 - java JDBC : Caused by: java.sql.SQLException: Numeric Overflow JDBC callableStatement.setDouble()获取“ Infinity”不是有效的数字或近似数字值 - JDBC callableStatement.setDouble() getting 'Infinity' is not a valid numeric or approximate numeric value Spring 数据、Oracle DB、java.sql.SQLException:数字溢出 - Spring data, Oracle DB, java.sql.SQLException: Numeric Overflow 什么时候在SQLException中得到“'NaN'不是有效的数值或近似数值”? - When do we get “'NaN' is not a valid numeric or approximate numeric value” in SQLException? (JTDS)java.sql.SQLException:将数据类型nvarchar转换为numeric时出错 - (JTDS) java.sql.SQLException: Error converting data type nvarchar to numeric java.sql.SQLException:没有为参数2指定值 - java.sql.SQLException: No value specified for parameter 2 java.sql.SQLException:没有为参数 6 指定值 - java.sql.SQLException :no value specified for parameter 6 java.sql.SQLException: 没有为参数 1 指定值 - java.sql.SQLException: No value specified for parameter 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM