Derek Mahar
Derek Mahar

Reputation: 28386

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?

Upvotes: 9

Views: 15092

Answers (3)

APC
APC

Reputation: 146239

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 ?

Upvotes: 2

user330315
user330315

Reputation:

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

Upvotes: 11

OMG Ponies
OMG Ponies

Reputation: 332581

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...

Upvotes: 1

Related Questions