1
我在我的MySQL表中有3列,2是INT和一個VARCHAR。Spring Jdbc模板返回Int作爲長?
我得到類轉換異常:java.lang.ClassCastException:java.lang.Long不能轉換爲java.lang.Integer。繼承人我的代碼:
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);
}
我的問題是爲什麼我必須將它投到龍?是否因爲MySQL中允許的最大INT值和java允許的最大int值不同?