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.
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:Reference
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.
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.