how to store BigInteger values in oracle database.
Posted
by Bipul
on Stack Overflow
See other posts from Stack Overflow
or by Bipul
Published on 2010-06-16T11:22:50Z
Indexed on
2010/06/16
11:32 UTC
Read the original article
Hit count: 392
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.
© Stack Overflow or respective owner