Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast bigint to long

I am getting data from a database. I am getting classcastexception. In database my id is saved as BIGINT but in code(object) it is long. Is there is any problem while casting bigint to long?

like image 923
Muhammad Imran Tariq Avatar asked Apr 05 '11 14:04

Muhammad Imran Tariq


2 Answers

have you tried casting your value to BigInteger first and then get the long value with longValue()? It should work. And aioobe is right, check for null values also.

cheers!

like image 129
Lucas de Oliveira Avatar answered Oct 03 '22 01:10

Lucas de Oliveira


If this is MySql, you should probably use java.math.BigDecimal.

See the table at Java, JDBC and MySQL Types.

enter image description here

like image 29
aioobe Avatar answered Oct 03 '22 00:10

aioobe