zoukankan      html  css  js  c++  java
  • JAVA-查看MongoDB中的数据(包含List集合)

    package com.xinsight.server;
    
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.mongodb.BasicDBObject;
    import com.mongodb.DB;
    import com.mongodb.DBCollection;
    import com.mongodb.DBCursor;
    import com.mongodb.DBObject;
    import com.mongodb.Mongo;
    import com.xinsight.Util.BeanUtil;
    import com.xinsight.Util.InitMongodb;
    import com.xinsight.Util.Manager;
    import com.xinsight.server.model.PhoneEntity;
    /**
     *查找Mongodb中列中的List集合 
     */
    public class FindMongodbServer {
        public static void main(String args[]){
            try {
                Mongo mg = new Mongo("localhost",27017);
                DB db = mg.getDB("admin");
                if(db.authenticate("aa", "aa".toCharArray())){
                    db = mg.getDB("dxtext");
                    DBCollection dbc = db.getCollection("zq1");
                    DBCursor u = dbc.find();
                    while(u.hasNext()){
                        String n = "";
                        BasicDBObject obj = (BasicDBObject)u.next();
                        ArrayList<BasicDBObject> list = (ArrayList<BasicDBObject>)obj.get("l");
                        for(BasicDBObject basi : list){
                            n += basi.getString("n") + "_" + basi.getString("t") + "#";  //将list中的数据拼接
                        }
                        n = n.substring(0, n.length() - 1);
                        System.out.println(n);
                        int sum = 0;  //总共接听电话次数
                        String strs[] = n.split("#");
                        for(int i = 0;i < strs.length;i++){
                            int a = Integer.parseInt(strs[i].split("_")[1]);
                            sum +=a;
                        }
                        System.out.println(obj.get("n") + "  " + sum);  //主叫号码     总共接听次数
                        System.out.println("----------------------");
                        Thread.sleep(1000);
                    }
                }
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    stax(和dom4j功能一样,这个是基于流的一种处理方式)
    JAXB(xml和对象的转换)
    wsdl理解
    webservice心得
    ZT 分智网博客 – 职场、面试技巧、职业规划
    discern concern fifth sixth
    ZT I Believe I Can Fly(我相信我能飞)
    ZT 理解class.forName()
    ZT 第9章 Framework的启动过程
    android 智能指针的学习先看邓凡平的书扫盲 再看前面两片博客提升
  • 原文地址:https://www.cnblogs.com/zqzdong/p/4839015.html
Copyright © 2011-2022 走看看