Spring queryforint method: int type single value query
•
Java
Grammar 1
queryForInt(String sql)
Example
public int getUserCount(){
String sql = "SELECT count(*)FROM tb_user"; //创建一条sql语句
int count = getJdbcTemplate().queryForInt(sql); //执行sql语句,把查询的结果赋值给一个int类型变量
return count;
}
Grammar 2
queryForInt(String sql,Object[] args)
Example
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;
}
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
二维码
