今天才发现,原来spring 3.2.2之后,jdbctemplate中的queryForInt已经被取消了!
看下代码:
原来是这样写的:
1 String sql = "SELECT count(*) FROM USERS WHERE username = ?"; 2 boolean result = false; 3 4 5 int count = getJdbcTemplate().queryForInt(sql, new Object[] { username }); 6 7 f (count > 0) { 8 result = true;
现在,全部用queryForObject了(包括queryForLong),就是说:
1 int count = getJdbcTemplate().queryForObject( 2 sql, new Object[] { username }, Integer.class);
观察其代码,的确可以看到是@deprectd了
1 package org.springframework.jdbc.core; 2 3 public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { 4 5 //... 6 @Deprecated 7 public long queryForLong(String sql, Object... args) throws DataAccessException { 8 Number number = queryForObject(sql, args, Long.class); 9 return (number != null ? number.longValue() : 0); 10 } 11 12 @Deprecated 13 public int queryForInt(String sql, Object... args) throws DataAccessException { 14 Number number = queryForObject(sql, args, Integer.class); 15 return (number != null ? number.intValue() : 0); 16 }