queryForInt(String sql)
引數說明:public int getUserCount(){ String sql = "SELECT count(*)FROM tb_user"; //建立一條SQL語句 int count = getJdbcTemplate().queryForInt(sql); //執行SQL語句,把查詢的結果賦值給一個int型別變數 return count; }
queryForInt(String sql,Object[] args)
引數說明:public int getUserCount(){ String sql = "SELECT count(*)FROM tb_user WHERE sex=?and age=?"; //建立一條SQL語句 Object[] args = {"男",27}; int count = getJdbcTemplate().queryForInt(sql,args); //執行SQL語句 return count; }