spring 3.2.2后springjdbc中不用queryforInt了

  今天才发现,原来spring 3.2.2之后,jdbctemplate中的queryForInt已经被取消了!
看下代码:

  原来是这样写的:
   
   String sql = "SELECT count(*) FROM USERS WHERE username = ?";
        boolean result = false;
 
      
        int count = getJdbcTemplate().queryForInt(sql, new Object[] { username });
 
	if (count > 0) {
		result = true;
	}
 


   现在,全部用queryForObject了(包括queryForLong),就是说:

int count = getJdbcTemplate().queryForObject(
                        sql, new Object[] { username }, Integer.class);



    观察其代码,的确可以看到是@deprectd了
package org.springframework.jdbc.core;
 
public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
 
  //...
  @Deprecated
  public long queryForLong(String sql, Object... args) throws DataAccessException {
	Number number = queryForObject(sql, args, Long.class);
	return (number != null ? number.longValue() : 0);
  }
 
  @Deprecated
  public int queryForInt(String sql, Object... args) throws DataAccessException {
	Number number = queryForObject(sql, args, Integer.class);
	return (number != null ? number.intValue() : 0);
  }

你可能感兴趣的:(Spring 3)