简体   繁体   English

什么Java数据类型对应于Oracle SQL数据类型NUMERIC?

[英]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.

相关问题 哪种Java数据类型对应于Oracle SQL数据类型NUMERIC / DECIMAL,并获得PLSQL的等效Java代码? - What Java data type corresponds to the Oracle SQL data type NUMERIC/DECIMAL and get equivalent Java code for PLSQL? 在Java中使用SQL语句插入数字数据类型 - Inserting numeric data type using SQL statement in Java 将ORACLE数据类型映射到JAVA数据类型 - Mapping ORACLE Data Type to JAVA Data Type 哪个Java数据类型对应postgresql“没有区域的时间” - Which Java data type corresponds to postgresql “time without zone” 我在sql中有数字类型,pojo类中对应的映射数据类型是什么 - I have numeric type in sql what is the corresponding mapping data type in pojo class 在运行时从数据类型oracle检测数据类型java - Detect data type java from Data Type oracle in run time Java中图像的数据类型是什么 - What is the data type for images in java Java中STRUCT的数据类型是什么? - What data type is STRUCT in java? Spring 数据、Oracle DB、java.sql.SQLException:数字溢出 - Spring data, Oracle DB, java.sql.SQLException: Numeric Overflow 在Java中,将大double作为参数传递给sql server,从而导致“将数据类型varchar转换为数值时出错”。 - In Java, pass large double as parameter to sql server, causing “Error converting data type varchar to numeric.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM