| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
GerD82
9年前发布

Java MongoDAO 初始化

[Java]代码    

private DB getMongoDB() {     try {         if (MONGODB_DB == null) {             Mongo mgo = new Mongo(ip, port);             DB db = mgo.getDB(mongodbName);             char[] pwd = password.toCharArray();             db.authenticate(user, pwd);               MongoOptions options = mgo.getMongoOptions();             options.socketTimeout = 2000;             options.autoConnectRetry = true;             options.socketKeepAlive = true;               db.addOption(Bytes.QUERYOPTION_NOTIMEOUT);             MONGODB_DB = db;              return db;         } else {             return MONGODB_DB;         }     } catch (Exception e) {         e.printStackTrace();         return null;     } }