ResultSetMetaData returns BigDecimal insted from int

Need help regarding jdbc metadata. I am using ResultsetMetaData to retrieve the metadata of table columns in Oracle10g . I am using ojdbc14.jar. The table ID contains the Number field. This field is read using jdbc at run time to retrieve metadata attributes. ResultSetMetaData.getColumnClassName () returns java.math.BigDecimal , while I expect it to be integer or int or long or long. I even tried to create a table with an instruction with an explicit definition of type int for the ID column as

CREATE TABLE COST_DETAILS ( ID **INT** Primary Key...

but still, ResultSetMetaData returns a BigDecimal column for the identifier.

Is there a way to create a table with any specific column type so that it returns an int / long type?

or is ResultsetMetaData always returns BigDecimal for Oracle.

+3
source share
2 answers

I think that Oracle numbers will always be displayed in BigDecimal, since Oracle does not save them as a binary int, so this is an exact mapping. Oracle datatypes and Oracle JDBC you can do floating point numbers come in binary

+4
source

No. It is up to the driver.

You might have something like:

if( class == "BigDecimal" ) {
    return "Integer" 
} else if ( .... 

And return an integer, not a bigdecimal. This is what most people do.

0
source

Source: https://habr.com/ru/post/1717592/


All Articles