Spring queryforlong method: single value query method of long type

Grammar 1

queryForLong(String sql)

Example

public long getUserCount(){
  String sql = "SELECT count(*)FROM tb_user";  //创建一条sql语句
  long count = getJdbcTemplate().queryForLong(sql);  //执行sql语句
  return count;
}

Grammar 2

queryForLong(String sql,Object[] args)

Example

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;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>