Oracle JDBC:双倍下溢 [英] Oracle JDBC: underflow in double

查看:181
本文介绍了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();
}

  • 在插入/更新语句中使用双打之前,我是否必须检查并四舍五入?
  • 我能以某种方式自动将值取整吗?
  • 感谢您的见解/提示.

    推荐答案

    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:双倍下溢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆