The equivalent of Java long in the context of MySQL variables is BigInt. In Java, the long datatype takes 8 bytes while BigInt also takes the same number of bytes.
The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. The members of the BigInteger type closely parallel those of other integral types (the Byte, Int16, Int32, Int64, SByte, UInt16, UInt32, and UInt64 types).
In C#, long is mapped to Int64. It is a value type and represent System. Int64 struct. It is signed and takes 64 bits.
A big integer is a binary integer with a precision of 63 bits. The range of big integers is -9223372036854775808 to +9223372036854775807.
That corresponds to the long (or Int64), a 64-bit integer.
Although if the number from the database happens to be small enough, and you accidentally use an Int32, etc., you'll be fine. But the Int64 will definitely hold it.
And the error you get if you use something smaller and the full size is needed? A stack overflow! Yay!
Int64
maps directly to BigInt
.
Source
I just had a script that returned the primary key of an insert and used a
SELECT @@identity
on my bigint primary key, and I get a cast error using long - that was why I started this search. The correct answer, at least in my case, is that the type returned by that select is NUMERIC which equates to a decimal type. Using a long will cause a cast exception.
This is one reason to check your answers in more than one Google search (or even on Stack Overflow!).
To quote a database administrator who helped me out:
... BigInt is not the same as INT64 no matter how much they look alike. Part of the reason is that SQL will frequently convert Int/BigInt to Numeric as part of the normal processing. So when it goes to OLE or .NET the required conversion is NUMERIC to INT.
We don't often notice since the printed value looks the same.
Use a long datatype.
You can use long
type or Int64
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