JAVA连接mangodb

  /*
  *连接数据库
  */
  public
static boolean FaqDBCon(){ boolean flag = false; try{
       //db服务器地址,端口  MongoClient mongoClient
= new MongoClient("192.168.96.99",27017);
       //数据库名称 mongodatabase
= mongoClient.getDatabase("WeichatMongo"); System.out.println("Connect to database successfully"); }catch(Exception e){ System.out.println(e.getClass().getName()+":"+e.getMessage()); } return flag; } /*
  *连接数据库实例
  */
public static boolean FaqGetCollections(){ boolean flag = false;
     //连接实例名称 collectionNames
= mongodatabase.getCollection("faq"); System.out.println("Get Collection successfully"); return flag; }

 

posted @ 2017-12-15 09:49  dajiede  阅读(455)  评论(0编辑  收藏  举报