从一个SQL语句里查询出的结果,封装到HashMap里,select * from users where type="" order by id desc limit 50 type值是1,2,3,4,5 表示不同的会员类型值,这个type值是个参数变值我要把根据分类类型,取得排名为前50名的数据,封装到一个HashMap里面HashMap的  的key键值    是type值
HashMap的  的value键值  是 new bean(查询数据库时的时间,rs.getString(1),rs.getString(2))
HashMap的values键值,也是个类集合对象,我的功能就是这个HashMap,要把根据不同的类型参数值,把该类型的用户值前50名,封装成一个集合。因为我刚学,不知道如何把数据库里的查询,按这个要求,封装好因为小弟分不多,有没有谁愿意帮助我,把这代码写出来,小弟感激不进

解决方案 »

  1.   

    HashMap quertMap = new HashMap();
    for(.....){
    queryMap.put(type,rs.getString(i))
    }
      

  2.   

    private static final String SQL = "select * from users where type= ? order by id desc limit 50 "class.forname()
    connection conn = DriverManager.getconnection(...,..,...);prepareStatement ps = conn.xxxxxxResultSet rs = ps.executequery(sql);for(/......){
    String[] st = new String[rs.getmeta().getcluncount()];
    st[i] = rs.getString(1);
    }
    HashMap quertMap = new HashMap();
    for(.....){
    queryMap.put(type,st[i])
    }主要过程就这些了,有错误你自己单步调试了
      

  3.   

    想请问下limit 50 是什么意思?在SQL SERVER中能用么?
      

  4.   

    为啥我在SQL SERVER 的查询分析器中不能实现呢
      

  5.   

    把select出来的数据放到一个List里面更好些,因为你搜索到的数据会有多条。
    要用数据的时候直接使用:
    ((HashMap)list.get(i)).get("item").toString()  就可以得到数据。
    其中:list.get(i)得到搜索到的数据中的第i条;
    item对应的是你的表users中的列名。e.g:select a from user                -------这里的“a”就是对应item