Oracle JDBC:双倍下溢

编程入门 行业动态 更新时间:2024-10-11 15:16:37
本文介绍了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.

    参考:

    • docs.oracle /cd/E11882_01/timesten.112/e21642/types.htm#TTSQL124

更多推荐

Oracle JDBC:双倍下溢

本文发布于:2023-10-24 20:52:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双倍   Oracle   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!