how to store BigInteger values in oracle database

后端 未结 4 1273

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?

相关标签:
4条回答
  • 2021-01-13 12:46

    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

    0 讨论(0)
  • 2021-01-13 12:47

    You can use a decimal/numeric value depending on your db limits.

    0 讨论(0)
  • 2021-01-13 12:59

    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.

    0 讨论(0)
  • 2021-01-13 13:13

    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);
    
    0 讨论(0)
提交回复
热议问题