public CreatePage  srCreatePage(TbInfo tbInfo,String param,int pageSize,String currentP,String gowhich)
 {
 CreatePage  cp=new CreatePage();
 Criteria  c=this.getSession().createCriteria(TbInfo.class);
 if(param.equals("like"))
 {
 System.out.println("*************************************like");
 if(null != tbInfo)
  {
   if(tbInfo.getId()!=null)
   {
   System.out.println();
   c.add(Restrictions.eq("id",tbInfo.getId()));
   
   }
    if(tbInfo.getInfoTitle()!=null && !tbInfo.getInfoTitle().equals(""));
   {
   System.out.println("########################title"+tbInfo.getInfoTitle());
   c.add(Restrictions.like("infoTitle", tbInfo.getInfoTitle() , MatchMode.ANYWHERE ));
   }
   if(tbInfo.getInfoContent()!=null && !"".equals(tbInfo.getInfoContent()))
   {
   System.out.println("########################content"+tbInfo.getInfoContent());
   c.add(Restrictions.like("infoContent", tbInfo.getInfoContent(), MatchMode.ANYWHERE));
   }
   if(tbInfo.getInfoLinkman()!=null && !"".equals(tbInfo.getInfoLinkman()))
   {
   c.add(Restrictions.like("infoLinkman", tbInfo.getInfoLinkman(), MatchMode.ANYWHERE));
   }
   if(tbInfo.getInfoPhone()!=null && !"".equals(tbInfo.getInfoPhone()))
   {
   c.add(Restrictions.like("infoPhone", tbInfo.getInfoPhone(), MatchMode.ANYWHERE));
   }
   if( tbInfo.getInfoEmail()!=null && !"".equals(tbInfo.getInfoEmail()))
   {
   System.out.println("########################email"+tbInfo.getInfoEmail());
   c.add(Restrictions.like("infoEmail", tbInfo.getInfoEmail(), MatchMode.ANYWHERE));
   }
    
  }
 }
 else
 {
 System.out.println("*************************************all");
 if(null != tbInfo)
  {
   if(tbInfo.getId()!=null)
   {
   c.add(Restrictions.eq("id",tbInfo.getId()));
   
   }
    if(tbInfo.getInfoTitle()!=null && !tbInfo.getInfoTitle().equals(""));
   {
   c.add(Restrictions.like("infoTitle", tbInfo.getInfoTitle() , MatchMode.EXACT ));
   }
   if(tbInfo.getInfoContent()!=null && !"".equals(tbInfo.getInfoContent()))
   {
   c.add(Restrictions.like("infoContent", tbInfo.getInfoContent(), MatchMode.EXACT));
   }
   if(tbInfo.getInfoLinkman()!=null && !"".equals(tbInfo.getInfoLinkman()))
   {
   c.add(Restrictions.like("infoLinkman", tbInfo.getInfoLinkman(), MatchMode.EXACT));
   }
   if(tbInfo.getInfoPhone()!=null && !"".equals(tbInfo.getInfoPhone()))
   {
   c.add(Restrictions.like("infoPhone", tbInfo.getInfoPhone(), MatchMode.EXACT));
   }
   if(tbInfo.getInfoEmail()!=null && !"".equals(tbInfo.getInfoEmail()))
   {
   c.add(Restrictions.like("infoEmail", tbInfo.getInfoEmail(), MatchMode.EXACT));
   } 
  }
 }
   
  int count=((Integer)c.setProjection(Projections.rowCount()).uniqueResult()).intValue();
  System.out.println("%%%%%%%%%%%%%%%%%%%%count"+count);
 //String strCount=count.toString();
 cp.setAllr(count);//总记录数
 cp.setAllp();//总页数
 cp.setCurrentP(currentP);//当前页码
 cp.setPageInfo();//分页导航栏信息
 cp.setPageLink(gowhich);//分页状态显示信息
     
return cp;
 
 }
为什么 返回的记录是为0呢?
而且还有这样的异常
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select this_.id as id0_0_, this_.info_type as info2_0_0_, this_.info_title as info3_0_0_, this_.info_content as info4_0_0_, this_.info_linkman as info5_0_0_, this_.info_phone as info6_0_0_, this_.info_email as info7_0_0_, this_.info_date as info8_0_0_, this_.info_state as info9_0_0_, this_.info_payfor as info10_0_0_ from db_CityInfo.dbo.tb_info this_ where this_.id=? and this_.info_title like ? order by this_.info_date asc]; SQL state [null]; error code [0]; 只进 ResultSet 不支持请求的操作。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 只进 ResultSet 不支持请求的操作。

解决方案 »

  1.   

    没有数据肯定是没有满足where条件的数据把hibernate生成的sql粘出来运行下,就知道什么问题了,
      

  2.   

    Hibernate: 
        select
            count(*) as y0_ 
        from
            db_CityInfo.dbo.tb_info this_ 
        where
            this_.id=? 
            and this_.info_title like ?
    %%%%%%%%%%%%%%%%%%%%count0
    这是怎么回事呀 ?  
      

  3.   

    在hibernate操作下生成sql语句中 为什么有两个字段进行匹配呀,我只是测试的title这个字段,为什么还有id呢?  这是什么原因  ?
      

  4.   

    #######################id=0########################title=培训
    Hibernate: 
        select
            count(*) as y0_ 
        from
            db_CityInfo.dbo.tb_info this_ 
        where
            this_.id=? 
            and this_.info_title like ?
    %%%%%%%%%%%%%%%%%%%%count0
    从sql上可以看出title接受到值了,但是没有满足where的数据,还有id的值为空,不知道为什么sql语句中where条件中为什么还id这样的条件呢?
      

  5.   

    select this_.id as id0_0_, this_.info_type as info2_0_0_, this_.info_title as info3_0_0_, this_.info_content as info4_0_0_, this_.info_linkman as info5_0_0_, this_.info_phone as info6_0_0_, this_.info_email as info7_0_0_, this_.info_date as info8_0_0_, this_.info_state as info9_0_0_, this_.info_payfor as info10_0_0_ from db_CityInfo.dbo.tb_info this_ where this_.id=? and this_.info_title like ? order by this_.info_date asc检查Hibernate的映射配置文件,把SQL直接拷贝数据库里执行下看看,
      

  6.   


    if(tbInfo.getId()!=null)
    {
    c.add(Restrictions.eq("id",tbInfo.getId()));
      
    }
    满足if条件,进了这个,所以会多个id的条件
      

  7.   

    在hibernate操作下生成sql语句中 为什么有两个字段进行匹配呀,我只是测试的title这个字段,为什么还有id呢? 这是什么原因 ?