sqlname1="select count(id) from scott.person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;
              
ResultSet rt=stmt.executeQuery(sqlname1);
执行完这两条语句之后,不是应该得出一共是多少行的数据吗??因为 count(id) 所以不是应该得出来的是查询到多少行的数据,而不是数据集,如果想是数据集应该把count(id) 改为 *  ???????但是得出的结论是数据集,很奇怪啊!!

解决方案 »

  1.   

    和SQL本身的写法没有关系,用RS方法去解稀这条SQL得到的就是结果集,也就是说和方法本身有关!
      

  2.   

    sqlname1="select count(id) from scott.person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;sqlname1="select * from scott.person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;有什么不同吗??
      

  3.   

    sqlname1="select count(id) from scott.person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;
    结果为符合条件的记录ID的数量,只有一条记录,用
    rt.next();
    int num=rt.getInt(1)即可取得该数sqlname1="select * from scott.person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;
    结果为符合条件的记录集,包含scott.person 的全部字段,记录数为>=0
      

  4.   

    sqlname1="select count(id) from scott.person where (job  like '%"+key+"%' or iname like '%"+key+"%') and gzdd='"+gzdd+"' and job is not null order by id desc" ;这么做有什么好处吗?直接 count(*)出来不就是数字了吗,还不用rt.next(); int num=rt.getInt(1)这么麻烦才能取得值!