21.1. MongoDB
21.1.1. pom.xml
<dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver</artifactId> <version>3.2.2</version> </dependency>
21.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(); } } }
21.1.3. 读取操作
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。
时间: 2024-10-14 17:44:45