什么 Java 数据类型对应于 Oracle SQL 数据类型 NUMERIC?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3504521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What Java data type corresponds to the Oracle SQL data type NUMERIC?
提问by Derek Mahar
What Java data type does the Oracle JDBC driver assign to the Oracle SQL data type NUMERIC
? Does this vary with the size of the NUMERIC
type?
Oracle JDBC 驱动程序将哪种 Java 数据类型分配给 Oracle SQL 数据类型NUMERIC
?这是否随NUMERIC
类型的大小而变化?
回答by a_horse_with_no_name
As others have already said: the driver maps everything to BigDecimal, even if it's defined as NUMBER(38) (which could be mapped to BigInteger)
正如其他人已经说过的那样:驱动程序将所有内容映射到 BigDecimal,即使它被定义为 NUMBER(38)(可以映射到 BigInteger)
But it's pretty easy to find out what the driver maps. Simply do a getObject() on the column of the ResultSet and see which class the driver generated.
但是很容易找出驱动程序映射的内容。只需在 ResultSet 的列上执行 getObject() 并查看驱动程序生成的类。
Something like:
就像是:
ResultSet rs = statement.executeQuery("select the_number_column from the_table"); if (rs.next()) { Object o = rs.getObject(1); System.out.println("Class: " + o.getClass().getName()); }
回答by APC
According to the Oracle documentationit is java.math.BigDecimal
.
根据Oracle 文档,它是java.math.BigDecimal
.
"but my cast to BigDecimal throws a ClassCastException"
“但我对 BigDecimal 的转换抛出了 ClassCastException”
Have you tried using oracle.sql.NUMBER
?
你试过使用oracle.sql.NUMBER
吗?
回答by OMG Ponies
It's been a while, but I believe it's BIGINT in Java.It's BigDecimal. I remember the classcastexception you'd encounter would give a hint...
已经有一段时间了,但我相信它是 Java 中的 BIGINT。它是大十进制。我记得你遇到的 classcastexception 会给出一个提示......