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?
I m trying like this:
I have taken a column of number type in the database.
I converted BigInteger to BigDecimal like this:
BigInteger b=new BigInteger("5779857570957802579079");
Number n =b;
BigDecimal d=(BigDecimal)n;
PreparedStatement pstmt=con.prepareStatemant("insert into database values(?,?)");
pstmt.setString(1,"john");
pstmt.setBigDecimal(2,d);
I am getting the following exception:
javax.servlet.ServletException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.math.BigDecimal root cause java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.math.BigDecimal
Is there anything wrong in this code snippet? If there is, please suggest other methods.
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.