user3213490 user3213490 - 3 months ago 13
Java Question

extracting wrong value from database

I am inserting a long value into the database of 10 numeric digits. (example : 9876543219). It is saving the value in the database correctly. But when I try to extract the data from the database I am getting a different number like (1286608627).

Note: if the number is less than 10 digits everything is working fine.

I am using the following code to get the data from the database:

int getmyNumber = ((BigDecimal) TTRefermap.get("GET_MY_NUMBER")).intValue();


I can see the value of getMyNumber in Database as : 9876543219 (as expected).

Answer

use

long getmyNumber = ((BigDecimal) TTRefermap.get("GET_MY_NUMBER")).longValue();

because range of integer is only 2^31-1

or you can convert it to BigInteger as following:

BigInteger getmyNumber = ((BigDecimal) TTRefermap.get("GET_MY_NUMBER")).toBigInteger();