user.xml内    <select id="recordCount" resultClass="int">   
        SELECT count(*) as count FROM user   
    </select>
输出是个int,那么sqlMapClient怎么调用这个我用     public long getCount(){ 
     return (long) sqlMapClient.queryForList("recordCount");
    }错误。请问怎么使用recordCount???

解决方案 »

  1.   

    没用过ibatis,但是凭经验sqlMapClient.queryForList("recordCount"); 不是这样用吧。sqlMapClient.queryForInt("recordCount");或者返回回来的值是List,List里面的 Object[0]才是你要的值。
      

  2.   

    你的DAO extends BaseServiceImpl
    this.getCount(statementName, parameterObject)
      

  3.   


    哪有queryForInt阿。没有的。
      

  4.   

    我现在是这么做的。    public long getCount(){ 
         try {
         return Long.parseLong(sqlMapClient.queryForObject("recordCount").toString());
    } catch (NumberFormatException e) {
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return 0;
        }感觉怪怪的。使用queryForObject,之后转换成string,在强制转换成long。晕倒。哪位高人赐教一下,有没有类似sqlMapClient.queryForInt这种。直接就能取得xml内定义的输出int的统计数值!
      

  5.   

    sqlMapClient. 都点不出来,那就是没有。API文档上查找方法,没有定义类似的方法,那就没有了。
      

  6.   

    顶一下。希望使用ibatis的老手帮帮忙。sqlMapClient. 增删改 queryForObject、queryForList, 差不多就这么多。
      

  7.   

    resultClass="int"
    有这样的写法么?
    应该是resultClass="java.lang.Integer"
      

  8.   

    还有,既然你用的sqlMapClient.queryForList("recordCount"),怎么可能直接就返回long类型的值,如果只有一条数据那么要加上get(0),return (long)sqlMapClient.queryForList().get(0);如果有多条数据就要定义一个List来放数据然后再返回话说你做这个的时候都不看之前的例子么?如你标题所说,真的是非常简单的,但是没有身边的人请教么?还是你一个人自学?
      

  9.   


    网上看的例子,里面有这句。http://shiningwu.javaeye.com/blog/184117没人教阿。郁闷的很。(long)sqlMapClient.queryForList().get(0);
    基本上跟我的
    Long.parseLong(sqlMapClient.queryForObject("recordCount").toString());
    差别不大。
    我就是想看看有没有直接能获取到数值的查询。
      

  10.   

    我也是初学,好像是sqlMapClient.queryForObject()吧
      

  11.   

    用sqlMapClient.queryForObject()这个就可以了
      

  12.   

    补充一点,如果你用sqlMapClient.queryForList(),那么你的reslutClass就要改成"java.util.HashMap",如果是sqlMapClient.queryForObject(),就还是用"java.lang.Integer"