<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 閱讀(99) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 久久久国产精品亚洲一区| 亚洲日本va在线视频观看| 亚洲一区动漫卡通在线播放| AAA日本高清在线播放免费观看| 亚洲无线一二三四区手机| 男人免费视频一区二区在线观看 | 亚洲一区二区三区香蕉| 亚洲精品视频免费观看| 国产亚洲AV夜间福利香蕉149 | 一二三四免费观看在线电影| 亚洲性一级理论片在线观看| 成人在线免费看片| 亚洲愉拍一区二区三区| 在线播放免费播放av片| 鲁啊鲁在线视频免费播放| 亚洲精品国产精品乱码不卞| 一级毛片成人免费看a| 中文字幕亚洲专区| 一级毛片**不卡免费播| 亚洲人成黄网在线观看| 日韩成人在线免费视频| 亚洲视频在线免费| 亚洲成色999久久网站| 美女网站免费福利视频| 亚洲精品宾馆在线精品酒店| 亚洲中文无韩国r级电影| 久久国产乱子精品免费女| 亚洲视频国产视频| 国产精品嫩草影院免费| 中国一级特黄高清免费的大片中国一级黄色片| 亚洲国产精品成人久久| 中文字幕人成无码免费视频| h在线看免费视频网站男男| 亚洲国产一区国产亚洲| 女人张开腿等男人桶免费视频| 免费的黄色网页在线免费观看| 亚洲日韩区在线电影| 免费一级毛片一级毛片aa| 免费视频精品一区二区三区| 国产成人精品日本亚洲语音| 内射干少妇亚洲69XXX|