papyhardcore

Servlet de connexion

Sep 4th, 2014
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package com.aerolitec.database;
  2.  
  3. import com.mongodb.DB;
  4. import com.mongodb.MongoClient;
  5. import com.mongodb.MongoCredential;
  6. import com.mongodb.ServerAddress;
  7.  
  8. import javax.servlet.ServletContextEvent;
  9. import javax.servlet.ServletContextListener;
  10. import java.net.UnknownHostException;
  11. import java.util.Arrays;
  12.  
  13.  
  14. /**
  15.  * Created by Damien on 28/08/2014.
  16.  */
  17. public class MakeConnection implements ServletContextListener {
  18.  
  19.  
  20.     @Override
  21.     public void contextInitialized(ServletContextEvent sce) {
  22.  
  23.         MongoClient mongoClient = null;
  24.         MongoCredential credential = MongoCredential.createMongoCRCredential("damien","oauth","toto".toCharArray());
  25.         try {
  26.             mongoClient = new MongoClient(new ServerAddress("localhost"), Arrays.asList(credential));
  27.  
  28.         } catch (UnknownHostException e) {
  29.             e.printStackTrace();
  30.         }
  31.  
  32.         DB db = mongoClient.getDB("oauth");
  33.         Db.databse = db;
  34.  
  35.     }
  36.  
  37.     @Override
  38.     public void contextDestroyed(ServletContextEvent sce) {
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment