Why output of numeric field, at table above, show java.math.BigDecimal?
As per Oracle documentation on Datatypes and their Java Mappings:
NUMBER:
The NUMBER class provides conversions between the Oracle Number (lnxnum_t) data type and Java types byte[], byte, short, integer, long, float, double, String, BigInteger, and BigDecimal.
Understanding Type Maps:
The type map relates a Java class to the SQL type name of an Oracle object. This is a one-to-one mapping that is stored in a hash table as a key-value pair. When you read data from an Oracle object, the JDBC driver considers the type map to determine which Java class to use to materialize the data from the SQL object type. When you write data to an Oracle object, the JDBC driver gets the SQL type name from the Java class by calling the getSQLTypeName() method of the SQLData interface. The actual conversion between SQL and Java is handled by the driver.
This is default behaviour and you can find it on the getObject methods underlying return type. For a data type of NUMBER the return type is java.math.BigDecimal.
+-----------------+------------------------+------------------------+
| Oracle SQL Type | getObject() | getOracleObject() |
| | Underlying Return Type | Underlying Return Type |
+-----------------+------------------------+------------------------+
| CHAR | String | oracle.sql.CHAR |
| VARCHAR2 | String | oracle.sql.CHAR |
| LONG | String | oracle.sql.CHAR |
| NUMBER | java.math.BigDecimal | oracle.sql.NUMBER |
| RAW | byte[] | oracle.sql.RAW |
| LONGRAW | byte[] | oracle.sql.RAW |
| DATE | java.sql.Timestamp | oracle.sql.DATE |
+-----------------+------------------------+------------------------+
An example of understanding the Java return types on database specific data types are shown in an example on the Summary page referred below. Similar example was presented in my previous answer on this post.
Conclusion:
Return types are database driver specific. If you want to cast them for your convenience or for any other reason, you can make an explicit call, for example, like getDouble( columnNumber ) on NUMBER data type columns. You may require to handle precision and scale parts, of the returned number value, explicitly.
Refer to:
- Oracle's Built-in Data Types
- Summary of getObject() and getOracleObject() Return Types
- Valid SQL Datatype-Java Class Mappings