Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

第 20 章 NoSQL

目录

20.1. MongoDB
20.1.1. pom.xml
20.1.2. 插入操作
20.1.3. 读取操作

20.1. MongoDB

20.1.1. pom.xml

			
<dependency>
	<groupId>org.mongodb</groupId>
	<artifactId>mongodb-driver</artifactId>
	<version>3.2.2</version>
</dependency>
			
			

20.1.2. 插入操作

			
package cn.netkiller.controller;

import java.net.UnknownHostException;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;

public final class Tracker {

	public Tracker() {
	
	}
	
	public static void main(String[] args) {
	
		MongoClient mongo = null;
		try {
			mongo = new MongoClient("192.168.4.1", 27017);
			
			DB db = mongo.getDB("finance");
			DBCollection table = db.getCollection("tracker");
			BasicDBObject document = new BasicDBObject();
			document.put("test", "helloworld");
			table.insert(document);
		} catch (UnknownHostException e) {
		e.printStackTrace();
		}
	}
}			
			
			

20.1.3. 读取操作