<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 495,  comments - 11,  trackbacks - 0

    1.準(zhǔn)備

    ???? 下載Mongo Java Driver,下載地址:https://github.com/downloads/mongodb/mongo-java-driver/mongo-2.5.3.jar

    ???? 如果是使用maven編譯,可在pom.xml文件中加入如下依賴

    ???? <dependency>
    ????????? <groupId>org.mongodb</groupId>
    ????????? <artifactId>mongo-java-driver</artifactId>
    ????????? <version>2.5.3</version>
    ???? </dependency>

    2.上程序

    /**
    ?* MongoDB學(xué)習(xí)之HelloWorld
    ?*
    ?* @author <a href="mailto:gerald.chen@qq.com">GeraldChen</a>
    ?* @version $Id: HelloWorldTest.java,v 1.1 2011/05/26 12:42:45 gerald.chen Exp $
    ?*/
    public class HelloWorldTest {

    ????? /** 數(shù)據(jù)庫(kù)連接IP */
    ???? public static final String DB_HOST = "192.168.35.101";

    ???? /** 數(shù)據(jù)庫(kù)連接端口 */
    ???? public static final int DB_PORT = 27017;

    ???? public static void main(String[] args) throws Exception {
    ???????? // connect to mongoDB, ip and port number
    ???????? Mongo mongo = new Mongo(DB_HOST, DB_PORT);

    ???????? // get database from MongoDB,
    ???????? // if database doesn't exists, mongoDB will create it automatically
    ???????? DB db = mongo.getDB("test_db");

    ???????? // Get collection from MongoDB, database named "yourDB"
    ???????? // if collection doesn't exists, mongoDB will create it automatically
    ???????? DBCollection collection = db.getCollection("test_collection");

    ???????? // create a document to store key and value
    ???????? BasicDBObject document = new BasicDBObject();
    ???????? document.put("id", 1001);
    ???????? document.put("message", "hello world mongoDB in Java");

    ???????? // save it into collection named "yourCollection"
    ???????? collection.insert(document);

    ???????? // search query
    ???????? BasicDBObject searchQuery = new BasicDBObject();
    ???????? searchQuery.put("id", 1001);

    ???????? // query it
    ???????? DBCursor cursor = collection.find(searchQuery);

    ???????? // loop over the cursor and display the retrieved result
    ???????? while (cursor.hasNext()) {
    ????????????????? System.out.println(cursor.next());
    ???????? }
    ???????? System.out.println("Done");
    ???}

    }

    2.程序輸出


    關(guān)鍵詞:HelloWorld?? MongoDB?? NoSQL?? JAVA??? 程序?? 軟件?? 數(shù)據(jù)庫(kù)?? 程序員
    ?

    posted on 2011-05-26 20:47 jadmin 閱讀(99) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 未满十八18禁止免费无码网站| 午夜小视频免费观看| 亚洲精品日韩中文字幕久久久| 我的小后妈韩剧在线看免费高清版| 在线综合亚洲欧洲综合网站| 亚洲精品国产综合久久一线| 久章草在线精品视频免费观看| 亚洲人成电影院在线观看| 全免费a级毛片免费**视频| 在线视频网址免费播放| 亚洲a∨无码男人的天堂| 亚洲成av人在片观看| 久久精品视频免费看| 337P日本欧洲亚洲大胆精品| 亚洲国产精品一区| 午夜亚洲福利在线老司机| 毛片免费全部播放无码| a高清免费毛片久久| 精品亚洲AV无码一区二区三区 | 四虎影视在线永久免费观看| 国产高清不卡免费视频| 朝桐光亚洲专区在线中文字幕| 亚洲美女激情视频| 亚洲一区日韩高清中文字幕亚洲 | 久久精品视频亚洲| 亚洲丰满熟女一区二区v| 亚洲精品国产电影| 久久久久亚洲精品无码网址| 人与动性xxxxx免费| 亚洲午夜电影在线观看| 亚洲第一区精品日韩在线播放| 1a级毛片免费观看| 一个人晚上在线观看的免费视频 | 最近的中文字幕大全免费版| 成全高清在线观看免费| 黄色免费网址在线观看| 亚洲精品国产高清在线观看| 亚洲精品视频观看| 亚洲成AV人在线播放无码| 亚洲中文字幕无码专区| 成人免费无码精品国产电影|