[英]What Java data type corresponds to the Oracle SQL data type NUMERIC?
What Java data type does the Oracle JDBC driver assign to the Oracle SQL data type NUMERIC
? Oracle JDBC驱动程序为Oracle SQL数据类型
NUMERIC
分配了哪些Java数据类型? Does this vary with the size of the NUMERIC
type? 这是否随
NUMERIC
类型的大小而变化?
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()); }
According to the Oracle documentation it 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
吗?
It's been a while, but I believe it's BIGINT in Java.
已经有一段时间了,但我相信它是Java中的BIGINT。
It's BigDecimal. 这是BigDecimal。 I remember the classcastexception you'd encounter would give a hint...
我记得你遇到的classcastexception会给出一个提示......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.