String sql="";
String loginedUser=this.getUserService().getCount("User", sql);//总注册人数
request.getSession().setAttribute("loginedUser", loginedUser);
String month=Util.getCurrentDate("yyyyMM");
sql="where regDate like '%"+month+"%'";
String loginedMonth=this.getUserService().getCount("User", sql);//本月注册人数
request.getSession().setAttribute("loginedMonth", loginedMonth);
String today=Util.getCurrentDate("yyyyMMdd");
sql="where lastLoginDate like '%"+today+"%'";
String todayVisit=this.getUserService().getCount("User", sql);//今日会员访问人数
request.getSession().setAttribute("todayVisit", todayVisit);看上面的代码,都是要查询User表中不同条件下的人数,这样的话没执行一次getCount()方法就要链接一次数据库,效率不高,能不能写的简化一些,使得效率高一些。getCount()方法如下:
public String getCount(String tableName, String condition) {
String hql = "select count(*) from " + tableName + " " + condition;
String tmp = this.getSession().createQuery(hql).list().get(0).toString();
return tmp;
}
String loginedUser=this.getUserService().getCount("User", sql);//总注册人数
request.getSession().setAttribute("loginedUser", loginedUser);
String month=Util.getCurrentDate("yyyyMM");
sql="where regDate like '%"+month+"%'";
String loginedMonth=this.getUserService().getCount("User", sql);//本月注册人数
request.getSession().setAttribute("loginedMonth", loginedMonth);
String today=Util.getCurrentDate("yyyyMMdd");
sql="where lastLoginDate like '%"+today+"%'";
String todayVisit=this.getUserService().getCount("User", sql);//今日会员访问人数
request.getSession().setAttribute("todayVisit", todayVisit);看上面的代码,都是要查询User表中不同条件下的人数,这样的话没执行一次getCount()方法就要链接一次数据库,效率不高,能不能写的简化一些,使得效率高一些。getCount()方法如下:
public String getCount(String tableName, String condition) {
String hql = "select count(*) from " + tableName + " " + condition;
String tmp = this.getSession().createQuery(hql).list().get(0).toString();
return tmp;
}
解决方案 »
- 关于企业组织和权限管理
- Extjs4.0 分页问题,数据不能显示
- j2ee框架总是提示<include file="struts-default.xml" />Included file cannot be found
- 求一个jsp网页计数器程序,有防止刷新功能
- 急救!简单的STRUTS问题
- 我现在需要将几个汉字转化为unicode,请介绍一种简单的转化方法
- 如何解决jsp访问oracle产生的这个ora-00600的问题?
- 济南的进来看看
- 一种关于velocity的模式,请各位指教.
- spring mvc 404错误
- 菜鸟求救——邮件自动发送系统~
- jsp页面提交数据到servlet处理,之后返回到另外一个jsp页面,怎样避免刷新重复提交?
比如本月注册用户,你可以专门建个表
month | count | year
1 100 2009有一个注册,更新下。查询的时候直接查询这个就可以了,是不是比每次都
select count(*) 效率要高点呢
每次查询的时候,不必重新连接数据库。yes,就是这个意思,阁下有啥办法哇啦?
左外连接 left outer join 好像是在不同的表中用的吧?!