开发者

Cast bigint to long

I am getting data from a database. I am getting classcastex开发者_JAVA百科ception. 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?


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!


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

See the table at Java, JDBC and MySQL Types.

Cast bigint to long


I was getting error java.math.BigInteger cannot be cast to java.lang.Long because I was getting the BigInteger while querying using Spring Data native query, so then I've resolved using below code.

((BigInteger)nativeQuery.getSingleResult()).longValue()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜