Java MongoDAO 初始化

GerD82的头像 GerD82 -1 2016-04-13 07:34 0

 基本信息

× 1    × 1    × 1   

浏览数: 31528

分享时间: 2 年 前

3

[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;
		}

	

  • 273025的头像 273025 2016-05-16 17:01 代码数:0

    很不错

  • 放养笔记的头像 放养笔记 2016-06-28 18:53 代码数:0

    没有通用性

  • pevahanifo的头像 pevahanifo 2018-09-22 19:21 代码数:0

    This is highly information, crisp and clear. I think that everything has been described in systematic manner so that reader could get maximum information and learn many things.

    technology and business news

  • cixexey的头像 cixexey 2018-08-20 15:30 代码数:0

    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog, I will keep visiting this blog very often.SEO

  • cixexey的头像 cixexey 2018-08-21 20:04 代码数:0

    I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.justcannabis.ca

  • cixexey的头像 cixexey 2018-08-24 02:06 代码数:0

    nice bLog! its interesting. thank you for sharing....mobil

  • cixexey的头像 cixexey 2018-08-24 20:16 代码数:0

    I wish more authors of this type of content would take the time you did to research and write so well.  I am very impressed with your vision and insight.\

    Michigan Personal Injury Law Firm

您的评论: