<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.準備

    ???? 下載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學習之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 {

    ????? /** 數據庫連接IP */
    ???? public static final String DB_HOST = "192.168.35.101";

    ???? /** 數據庫連接端口 */
    ???? 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.程序輸出


    關鍵詞:HelloWorld?? MongoDB?? NoSQL?? JAVA??? 程序?? 軟件?? 數據庫?? 程序員
    ?

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

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 69影院毛片免费观看视频在线| 亚洲人成77777在线观看网| 国产成人综合亚洲一区| 久久久久久久91精品免费观看| 亚洲综合色丁香麻豆| 91香蕉在线观看免费高清| 久久亚洲国产精品五月天| 久99久精品免费视频热77| 久久久影院亚洲精品| 中文字幕视频免费| 亚洲免费中文字幕| 妞干网免费视频观看| 猫咪免费人成网站在线观看| 亚洲电影一区二区三区| 国产成人精品免费视频动漫| 亚洲jizzjizz在线播放久| 中文在线免费视频| 亚洲av中文无码乱人伦在线咪咕| 日本视频免费高清一本18| 亚洲毛片免费观看| 免费观看一级毛片| 噜噜噜亚洲色成人网站∨| 波多野结衣中文字幕免费视频| 国产亚洲中文日本不卡二区| 成人永久免费高清| 亚洲人成网站在线播放2019 | 日本免费在线观看| 麻豆亚洲AV永久无码精品久久 | 黄页免费视频播放在线播放| 久久综合亚洲色HEZYO国产| 亚洲国产激情在线一区| 国产一区二区免费在线| 亚洲乱码中文字幕小综合| 日本免费一区尤物| 黄色网站软件app在线观看免费 | 国产在线jyzzjyzz免费麻豆| 亚洲A∨精品一区二区三区下载| 亚洲香蕉成人AV网站在线观看| 99视频全部免费精品全部四虎| 国产精品亚洲二区在线| 亚洲AV美女一区二区三区|