第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

java直接操作mongodb語(yǔ)句

java直接操作mongodb語(yǔ)句

眼眸繁星 2019-05-31 07:02:59
java直接操作mongodb語(yǔ)句
查看完整描述

2 回答

?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

參考如下
public class MongoDBJDBC {
public static void main(String[] args) {
try {
// 實(shí)例化Mongo對(duì)象,連接27017端口
Mongo mongo = new Mongo("localhost", 27017);
// 連接名為yourdb的數(shù)據(jù)庫(kù),假如數(shù)據(jù)庫(kù)不存在的話,mongodb會(huì)自動(dòng)建立
DB db = mongo.getDB("test");
// Get collection from MongoDB, database named "yourDB"
// 從Mongodb中獲得名為yourColleection的數(shù)據(jù)集合,如果該數(shù)據(jù)集合不存在,Mongodb會(huì)為其新建立
DBCollection collection = db.getCollection("test1");
// 使用BasicDBObject對(duì)象創(chuàng)建一個(gè)mongodb的document,并給予賦值。
BasicDBObject document = new BasicDBObject();
//document.put("id", 1001);
//document.put("msg", "hello world mongoDB in Java");
// 將新建立的document保存到collection中去
//collection.insert(document);
// 創(chuàng)建要查詢的document
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("name", "chen");
// 使用collection的find方法查找document
DBCursor cursor = collection.find(searchQuery);
// 循環(huán)輸出結(jié)果
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
System.out.println("Hello World");
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (MongoException e) {
e.printStackTrace();
}
}
}





查看完整回答
反對(duì) 回復(fù) 2019-06-01
?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

public class MongoDBJDBC {

    public static void main(String[] args) {

        try {

            // 實(shí)例化Mongo對(duì)象,連接27017端口

            Mongo mongo = new Mongo("localhost", 27017);

            // 連接名為yourdb的數(shù)據(jù)庫(kù),假如數(shù)據(jù)庫(kù)不存在的話,mongodb會(huì)自動(dòng)建立

            DB db = mongo.getDB("test");

            // Get collection from MongoDB, database named "yourDB"

            // 從Mongodb中獲得名為yourColleection的數(shù)據(jù)集合,如果該數(shù)據(jù)集合不存在,Mongodb會(huì)為其新建立

            DBCollection collection = db.getCollection("test1");

            // 使用BasicDBObject對(duì)象創(chuàng)建一個(gè)mongodb的document,并給予賦值。

            BasicDBObject document = new BasicDBObject();

            //document.put("id", 1001);

            //document.put("msg", "hello world mongoDB in Java");

            // 將新建立的document保存到collection中去

            //collection.insert(document);

            // 創(chuàng)建要查詢的document

            BasicDBObject searchQuery = new BasicDBObject();

            searchQuery.put("name", "chen");

            // 使用collection的find方法查找document

            DBCursor cursor = collection.find(searchQuery);

            // 循環(huán)輸出結(jié)果

            while (cursor.hasNext()) {

                System.out.println(cursor.next());

            }

            System.out.println("Hello World");

        } catch (UnknownHostException e) {

            e.printStackTrace();

        } catch (MongoException e) {

            e.printStackTrace();

        }

    }

}




查看完整回答
反對(duì) 回復(fù) 2019-06-01
  • 2 回答
  • 0 關(guān)注
  • 485 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)