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.
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()
精彩评论