一个使用矢量的例子!

    public static void main(String[] arg) {
        //new CommonUtil().readFile("c:/content.txt");
        Connection conn = null;
        try {
            //System.out.println(URLEncoder.encode("E:\\fish\\P0001\\中文", "UTF-8"));
            //System.out.println(URLEncoder.encode("E:\\fish\\P0001\\test","GBK"));
            //System.out.println(URLDecoder.decode("E%3A%5Cfish%5CP0001_02_txl%5CCoding%5Cwebtxl%5Cmyfile%5C1147094473625%5C%C4%BF%C2%BC", "GBk"));
            //Vector v = FileInfo.getAllFiles("E:\\fish\\P0001_02_txl\\Coding\\webtxl\\myfile\\1147094473625");
            //for (int i=0;i<v.size();i++) {
            //System.out.println(v.get(i));
            //}
            //DataOutputStream os = null;
            //DataInputStream is = null;
            //ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File("c:/test.zip")));
            //zos.setComment("zip by test");
            //zos.setMethod(ZipOutputStream.DEFLATED);
            // for (int i=0;i<v.size();i++) {
            //String fileName = v.get(i).toString();
            //String fileName ="E:\\fish\\P0001_02_txl\\Coding\\webtxl\\myfile\\1147094473625";
            //zip(zos, fileName, "");
            // }
            //zos.close();
            //DecimalFormat df1 = new DecimalFormat("###0.00");
            //System.out.println(df1.format(1.333333));
            Class.forName("com.jnetdirect.jsql.JSQLDriver");
            conn = DriverManager.getConnection(
                "jdbc:JSQLConnect://192.168.1.88:1433/canv", "sa", "canv");
            String sql = "select occupation,username from sync4j_user where occupation is not null and occupation <>'' order by occupation";
            DBUtil db = new DBUtil();
            ResultSet rs = (ResultSet) db.doSql(sql, db.QUERY_MODE, conn);
            List list = db.getListByRS(rs);
            int size = list.size();
            HashMap newlist = new HashMap();
            if (list != null && size > 0) {
                HashMap h = (HashMap) list.get(0);
                String temp = (String) h.get("occupation");
                Vector newv = new Vector();
                newlist.put(temp, newv);
                for (int i = 0; i < size; i++) {
                    h = (HashMap) list.get(i);
                    String occ = (String) h.get("occupation");
                    if (temp.equals(occ)) {
                        newv.add( (String) h.get("username"));

                    } else {
                        temp = occ;
                        newv = new Vector();
                        newv.add( (String) h.get("username"));
                        newlist.put(temp, newv);
                    }
                }
            }

          for (Iterator it = newlist.keySet().iterator();it.hasNext();) {
              String key = (String)it.next();
              Vector vt = (Vector)newlist.get(key);
              System.out.println(key+" :");
              for (int i=0;i<vt.size();i++) {
                  System.out.println(vt.get(i));
              }
          }

        } catch (Exception ex) {
            ex.printStackTrace();

        }finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            }catch (Exception e){}
        }

    }

posted @ 2006-05-31 09:17  QDuck  阅读(371)  评论(0编辑  收藏  举报