views:

244

answers:

2

Need some help regarding jdbc metadata. I am using ResultsetMetaData to get metadata of columns of a table on Oracle10g. I am using ojdbc14.jar. There is a field in table ID declared as Number . This field is being read with jdbc at runtime to get its metadata attributes. ResultSetMetaData.getColumnClassName() is returning java.math.BigDecimal while I am expecting it to be Integer or int or long or Long type. I even tried creating table with statement with explicitly defining int type for ID column as

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

but still ResultSetMetaData is returning BigDecimal for ID column.

Is there any way to create table with any particular column type so that it will retrun int/long type?

or is ResultsetMetaData always returns BigDecimal for Oracle.

A: 

No. That's up to the driver.

You can have something like:

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

And return integer instead of bigdecimal. That's what most people do.

OscarRyz
@Oscar: huh? where are you supposed to put that code?
Stephen C
In an auxiliary method used to determine which java type belongs to which sql type There is actually a class in apache utils library to do something like this, I can't find it though. Something like this: getJavaType( rsmd.getType( column ) ) ; // or something like that
OscarRyz
+3  A: 

I think Oracle numbers will always map to BigDecimal as Oracle does not store them as a binary int so this is an exact mapping. Oracle datatypes and Oracle JDBC You can make floating point numbers come as a binary

Mark