将 BigInteger 存储到 Mysql 中
由于数学限制,我必须使用 BigInteger 类来表示值。
经过一些计算后,我想将结果(由 2x BigInteger 实例给出)存储到 Mysql 中...
存储此类对象的最佳数据类型是什么?
我正在考虑使用 Blob 来存储这些结果的二进制格式(128 位)?但我想避免不必要的类型转换。
Due to mathematica constraints I've to use the BigInteger class to represent values.
After some calculations I would like to store the result (given by 2x BigInteger instances) into Mysql...
What is the best datatype to store such object ?
I was thinking about using a Blob to store the binary format of those results (128 bits) ? But I would like to avoid unnecessary type conversions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议使用 Blob,然后使用 BigInteger(byte[] val) 构造函数从字节数组转换为 BigInteger,然后使用 BigInteger#toByteArray() 方法来转换另一个方式。
I would recommend using a Blob and then the
BigInteger(byte[] val)
constructor to go from byte array to BigInteger, and theBigInteger#toByteArray()
method for the other way.参考
Reference
为了在 MySQL 中存储
bigInteger
值,我们可以存储为字符串:将
biginteger
转换为string
:将
s
存储在text 类型的表字段中
;例如,如果我们将s
存储在名为big_values
且具有字段big_value_as_string
的表中:该值现已存储。
要检索,我们必须:
从表中检索字符串值:
将字符串转换为
bigInteger
类型:In order to store
bigInteger
values in MySQL, we can store as strings:Convert
biginteger
tostring
:Store
s
in table field which is of typetext
; e.g. if we stores
in a table namedbig_values
having fieldbig_value_as_string
:The value is now stored.
To retrieve we must:
Retrieve string value from table:
Convert the string to
bigInteger
type:MySQL 有一个 BIGINT 数据类型,如下所示: http://dev .mysql.com/doc/refman/5.0/en/numeric-types.html
您可以尝试使用 BIGINT 来实现这一点,而不是转换为二进制格式,在我看来,这使得它变得更加复杂。
MySQL has a BIGINT data type as shown in: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
You can try to use the BIGINT for that rather then doing conversion to binary formats which makes it whole lot more complex to my opinion.