标签:class java com get 数据 string
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
/** *
用java 往mongoDB插入数据 * @author wwd
* */
public class InsertData {
public static void main(String[]args) throws UnknownHostException{
Mongo mongo=new Mongo("127.0.0.1",27017);//链接mongoDB
DB db=mongo.getDB("test");//获取test数据库
DBCollection collection=db.getCollection("user");//获取user集合
//向user集合插入一条数据
DBObject object=new BasicDBObject();
object.put("name", "李四");
object.put("age",23);
collection.insert(object);
}
}
mongoDB 插入数据 用java实现,布布扣,bubuko.com
标签:class java com get 数据 string
原文地址:http://www.cnblogs.com/wuweidu/p/3809055.html