本文介绍了Oracle JDBC:双倍下溢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当尝试将双精度型插入到Oracle表的 DOUBLE PRECISION 列中时,当双精度型超出范围(在我的情况下:太小)时,会出现异常,但仅当使用PreparedStatement(如果我使用普通的Statement,则将double舍入为0).
When trying to insert doubles into a DOUBLE PRECISION column of an Oracle table, I get an exception when the double is out of range (in my case: too small), but only when using PreparedStatement (if I use the normal Statement, it rounds the double to 0).
表格:
create table test ( VALUE DOUBLE PRECISION );Java代码:
double d = 1e-234; // using Statement works, the number gets rounded and 0 is inserted try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into test values (" + d + ")"); } // using PreparedStatement fails, throws an IllegalArgumentException: Underflow try (PreparedStatement stmt = conn.prepareStatement("insert into test values (?)")) { stmt.setDouble(1, d); stmt.executeUpdate(); }
- 在插入/更新语句中使用双打之前,我是否必须检查并四舍五入?
- 我能以某种方式自动将值取整吗?
- docs.oracle /cd/E11882_01/timesten.112/e21642/types.htm#TTSQL124
感谢您的见解/提示.
推荐答案DOUBLE PRECISION = FLOAT(126).
使用BINARY_DOUBLE数据类型具有与Java Double相同的精度.
Use the BINARY_DOUBLE data type to have the same precision as a Java Double.
参考:
更多推荐
Oracle JDBC:双倍下溢
发布评论