如何在oracle数据库中存储BigInteger值 [英] how to store BigInteger values in oracle database
问题描述
我使用JDBC将Java程序连接到Oracle数据库。我想在数据库中存储 BigInteger
值(512位)。该列的类型应该是什么?
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 have taken a column of number type in the database.
我将 BigInteger
转换为 BigDecimal
像这样:
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);
我收到以下异常:
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.
推荐答案
我没有直接回答你的问题,但我只看到一个oracle数据类型可以存储512位数字:varchar2(156)(156 = abs(log(2 ^ 512))+ 2)
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)
所以我宁愿将biginteger转换为一个字符串而不是一个大十字形。
So i would rather convert the biginteger to a string rather than a bigdecimal.
这篇关于如何在oracle数据库中存储BigInteger值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!