先说问题
select count(lunch_id) from swTelList   这条语句就是求出这个表中有多少条记录  我现在不知道怎么写这个DAO方法,就是说 我在页面上调用这个方法的时候就能得到这个表中有多少记录的数字      谢谢大家~~帮帮忙  请大家把这个DAO方法写一下 

解决方案 »

  1.   

    public Integer payEmolumentCount() throws Exception{
    Query q=hibernateSession.createQuery("select count(s.lunchId) from swTelList s");
    List list=q.list();
    return (Integer)list.get(0);
    }
      

  2.   


     public int count(){
      int count=0;
     String sql="select count(lunch_id) from swTelList";
     conn=this.getConnection();
     pstmt=conn.prepareStatement(sql);
     rs=pstmt.executeQuery();
     if(rs.next())
     {
       count=rs.getInt(1);
     }
     return count;
     }
      

  3.   


    public Integer payEmolumentCount() throws Exception{
        return ((Long)hibernateSession.createQuery("select count(s.lunchId) from swTelList s").uniqueResult()).intValue();      
    }
      

  4.   

    public int getSwTelListCount(){
        PreparedStatement ps = null;
         ResultSet rs = null;
        String sql = "select count(lunch_id) from swTelList";
         ps = conn.prepareStatement(sb.toString());
         rs = ps.executeQuery();
         int count = 0;
        if(rs.next()){
          count = rs.getInt(1);
      }
       return count;
    }
      

  5.   

    public int selectAllRows(Job job) {
    // TODO Auto-generated method stub
    int i=0;
    // 参数集合
    List condition = new ArrayList();
    // sql语句
    String sql = "select count(jobId) as num from tb_job where 1=1";
    // 条件
    //编号
    if (null != job.getNumber() && !"".equals(job.getNumber())) {
    sql += " and number like ?";
    condition.add("%"+job.getNumber()+"%");
    }
    //公司名称
    if (null != job.getCompanyName() && !"".equals(job.getCompanyName())) {
    sql += " and companyName like ?";
    condition.add("%"+job.getCompanyName()+"%");
    }
    //项目名称
    if (null != job.getProjectName() && !"".equals(job.getProjectName())) {
    sql += " and projectName like ?";
    condition.add("%"+job.getProjectName()+"%");
    }
    //当天工作
    if (null != job.getTjob() && !"".equals(job.getTjob())) {
    sql += " and tjob like ?";
    condition.add("%"+job.getTjob()+"%");
    }
    //完成情况
    if ( job.getCondition()>0 ) {
    sql += " and condition = ?";
    condition.add(job.getCondition());
    }
    //解决方案
    if (null != job.getProblemSolve() && !"".equals(job.getProblemSolve())) {
    sql += " and problemSolve like ?";
    condition.add("%"+job.getProblemSolve()+"%");
    }
    //备注
    if (null != job.getRe() && !"".equals(job.getRe())) {
    sql += " and re like ?";
    condition.add("%"+job.getRe()+"%");
    }
    //时间
    if (null != job.getTimes() && !"".equals(job.getTimes())) {
    sql += " and times like ?";
    condition.add("%"+job.getTimes()+"%");
    }
    // 执行查询
    Result result = super.searchTemplete(sql, condition);
    SortedMap[] map=result.getRows();
    if(map.length>0)
    {
    i=Integer.parseInt(map[0].get("num").toString());
    }
    // 清空
    sql = null;
    condition = null;
    return i;
    }
      

  6.   

    public int count(){
      int count=0;
     String sql="select count(lunch_id) from swTelList";
     conn=this.getConnection();
     pstmt=conn.prepareStatement(sql);
     rs=pstmt.executeQuery();
     if(rs.next())
     {
       count=rs.getInt(1);
     }
     return count;
     }
      

  7.   


    private String buildString(Map<String, Object> map) {
    StringBuffer conditionString = new StringBuffer();
    if(map.containsKey("t1")) {
    conditionString.append(" and T.t1 = '").append(map.get("t1")).append("'");
    }
    if(map.containsKey("t2")) {
    conditionString.append(" T.t2 like'%").append(map.get("t2")).append("%'");
    }
    return conditionString.toString();
    }
    public int getCountT(Map<String, Object> map) {
    BigDecimal bigNum = null;
    Session hibernateSession = getSession();
    try {
    String queryString = "select count(*) from Table T where 1 = 1"
    .concat(this.buildString(map));
    bigNum = (BigDecimal) hibernateSession.createSQLQuery(queryString).uniqueResult();
    if(bigNum != null) {
    return bigNum.intValue();
    }
    }catch (Exception ex) {
    ex.printStackTrace();
    }finally {
    hibernateSession.close();
    }
    return 0;
    }
      

  8.   

    String sql = "select count(*) from body where entId=" + eid;public int countRows(String sql) throws Exception {
    // TODO Auto-generated method stub
    Transaction trans = null;
    Session session = HibernateSessionFactory.getSession();
    trans = session.beginTransaction();
    int m = Integer.parseInt(session.createSQLQuery(sql).list().get(0)
    .toString());
    trans.commit();
    HibernateSessionFactory.closeSession();
    return m;
    }