What Java data type corresponds to the Oracle SQL data type NUMERIC?

Derek Mahar picture Derek Mahar · Aug 17, 2010 · Viewed 12.8k times · Source

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?

Answer

a_horse_with_no_name picture a_horse_with_no_name · Aug 17, 2010

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());
}