3

probably this is a real beginner question, but i cannot find an answer on the web. I have a Oracle db, with a table whose primary key is a NUMBER(16) and is filled with a sequence, whose max value is 999999999999999999999999999 .

what java type should i use to hold the sequence value ? long, biginteger or bigdecimal?

thank you in advance

2
  • Slight problem: 999999999999999999999999999 is too large for a NUMBER(16) column. Perhaps you meant 9999999999999999? Commented Oct 8, 2010 at 15:16
  • no you are right it's too large , unlucky this happens often, db administrators aren't so smart (or are too lazy), it's still on the development db so we don't waste time to change it yet. Anyway thank you to have point it out. Commented Oct 8, 2010 at 16:05

2 Answers 2

7

Long should do as it has a maximum value of 2^63 - 1

Sign up to request clarification or add additional context in comments.

Comments

1

Firstly, please use scientific notation for large numbers. It took me a good chunk of time to work out that the number you posted was 1027.

If I understand your question correctly, we can probably leave the database out of it. Am I right in thinking that your question boils down to "I need to store positive integers up to 10^27. What is the smallest data type that will fit this?"

If so, a quick google shows that longs will definitely fit. BigInteger and BigDecimal will both also definitely contain your number, since they're arbitrary precision, but you don't need them, and they'll likely make your code more clunky (due to not being primitives). So unless you specifically need the Bignum functionality and methods, use long. (And I can't see any reason why you'd use a BigDecimal over BigInteger for inputs that are definitely whole numbers).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.