[Solved] java.lang.Long cannot be cast to java.lang.Integer

I am using “select count (*) total count from student where SnO =?AND Password = ?” I encountered this problem when querying the number of satisfied conditions. At that time, my code was as follows:
object count = map. Get (“total count”); return (int)count;
I suspect that the type of the returned number is long, so I report an error because the integer is an unchangeable type, and long and integer have no inheritance relationship and cannot be converted

①.
long count = (long) map. Get (“totalcount”); return (int)count;
use long first, and then turn it strongly
②.
Number num = (Number)map.get(“TotalCount”);
return num.intValue();
because java.lang.number is the parent of integer and long

Similar Posts: