Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can java's Long hold a SQL BIGINT(20) value?

Tags:

java

sql

bigint

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)

like image 911
prime Avatar asked Jul 27 '15 15:07

prime


People also ask

What is the max value for BIGINT in SQL?

A big integer is a binary integer with a precision of 63 bits. The range of big integers is -9223372036854775808 to +9223372036854775807.

What is the max length of BIGINT in SQL Server?

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).

How much can BIGINT hold?

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.

What is BIGINT 20 SQL?

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) .


1 Answers

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.

like image 125
Leland Barton Avatar answered Oct 16 '22 22:10

Leland Barton