Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? Does this vary with the size of the NUMERIC type?

like image 415
Derek Mahar Avatar asked Aug 17 '10 16:08

Derek Mahar


3 Answers

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)

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.

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());
}
like image 92
a_horse_with_no_name Avatar answered Nov 12 '22 11:11

a_horse_with_no_name


According to the Oracle documentation it is java.math.BigDecimal.


"but my cast to BigDecimal throws a ClassCastException"

Have you tried using oracle.sql.NUMBER ?

like image 27
APC Avatar answered Nov 12 '22 11:11

APC


It's been a while, but I believe it's BIGINT in Java.It's BigDecimal. I remember the classcastexception you'd encounter would give a hint...

like image 30
2 revs Avatar answered Nov 12 '22 11:11

2 revs