我使用SQL语句查询的数据总数量,我想将总数量放在一个int变量中,应该怎么用呀?

String sql = "select count(*) from t_product";
 

之后应该怎么放进int num里面

执行这个sql 得到的数量 然后赋值给 num

sql 就是这样写 剩下的就是程序直接接收返回值就行

看你用的是hibernate还是mybatis

hibernate:

String hql = "select count(*) from t_product";
int num((Integer)getHibernateTemplate().iterate(hql).next()).intValue();