I have a table in an SQL database where the values' data type is BIGINT(20), and I need to get those data to my logic in Java for processing.
What should be the appropriate data type in java to store the BIGINT(20) value returned ?
(I thought of using Long but there is BigInteger also, can't figure out what is good or suitable)
A big integer is a binary integer with a precision of 63 bits. The range of big integers is -9223372036854775808 to +9223372036854775807.
The BigInt data type in SQL Server is the 64-bit representation of an integer. It takes up 8 bytes of storage. It can range from -2^63 (-9,223,372,036,854,775,808) to 2^63 (9,223,372,036,854,775,807).
BIGINT takes 8 bytes i.e. 64 bits. The signed range is -9223372036854775808 to 9223372036854775807 and unsigned range takes positive value. The range of unsigned is 0 to 18446744073709551615.
The 20 in INT(20) and BIGINT(20) means almost nothing. It's a hint for display width. It has nothing to do with storage, nor the range of values that column will accept. It's a common source of confusion for MySQL users to see INT(20) and assume it's a size limit, something analogous to CHAR(20) .
It depends on the database server. A Java long
is always implemented as 8 bytes since it is part of the standard.
On MSSQL, the bigint
type is 8 bytes, so it is a perfect match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With