queryForLong(String sql)
引數說明:public long getUserCount(){ String sql = "SELECT count(*)FROM tb_user"; //建立一條SQL語句 long count = getJdbcTemplate().queryForLong(sql); //執行SQL語句 return count; }
queryForLong(String sql,Object[] args)
引數說明:public long getUserCount(){ String sql = "SELECT count(*)FROM tb_user WHERE sex=?and age=?"; //建立一條SQL語句 Object[] args = {"男",27}; long count = getJdbcTemplate().queryForLong(sql,args); //執行SQL語句 return count; }