I have connected Java program to Oracle database using JDBC. I want to store BigInteger
values(512 bits) in the database. What should be the type of the column?
you can try this way:
oracle.sql.NUMBER numberValue = new oracle.sql.NUMBER(bigIntegerValue);
cs.setObject(id, numberValue, OracleTypes.NUMBER);
where bigIntegerValue
is an instance of java.math.BigInteger
, it works for me
You can use a decimal/numeric value depending on your db limits.
I'm not answering directly your question, but i only see one oracle datatype that can store a 512 bits number : varchar2(156) (156 = abs(log(2^512))+2)
So i would rather convert the biginteger to a string rather than a bigdecimal.
Both BigInteger and BigDecimal extend java.lang.Number, however this does not mean that you can cast from BigInteger up to Number then down to BigDecimal.
There is a constructor in BigDecimal that takes a BigInteger, so try:
BigDecimal d = new BigDecimal(b);