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

prime picture prime · Jul 27, 2015 · Viewed 11k times · Source

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)

Answer

Leland Barton picture Leland Barton · Jul 27, 2015

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.