how to store BigInteger values in oracle database.
- by Bipul
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.