I have 3 columns in my MySQL table, 2 are INTs and one VARCHAR.
I am getting class cast exception: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer. Heres my code:
List<Map<String, Object>> rows = getJdbcTemplate().queryForList(sql);
for (Map row : rows) {
Customer customer = new Customer();
// throws ClassCastException
// customer.setCustId((Integer)(row.get("CUST_ID")));
customer.setCustId((Long)(row.get("CUST_ID"))); // had to change custId field in bean to long
customer.setName((String)row.get("NAME"));
// work around
customer.setAge(((Long)row.get("AGE")).intValue());
customers.add(customer);
}
My question is why do i have to cast it to Long? Is it because the maximum allowed INT value in MySQL and the maximum allowed int value by java are not same?
MySQL primary key integers are unsigned, Java
ints are signed. Same number of bits, but the unsigned has a full 4G positive range.