Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  2. // TODO Auto-generated method stub
  3. String name = request.getParameter("age");
  4. boolean submitButtonPressed = request.getParameter("submit") != null;
  5. System.out.print(name);
  6. try{
  7. System.out.print(name);
  8. // To connect to mongodb server
  9. MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
  10. // Now connect to your databases
  11. DB db = mongoClient.getDB( "local" );
  12. DBCollection coll = db.getCollection("Employee");
  13. BasicDBObject gtQuery = new BasicDBObject();
  14. gtQuery.put("Age", new BasicDBObject("$gt", name).append("$lt", 50));
  15. DBCursor cursor = coll.find(gtQuery);
  16. int i=1;
  17. while (cursor.hasNext())
  18. {
  19. System.out.println("Inserted Document: "+i);
  20. System.out.println(cursor.next());
  21. i++;
  22. }
  23. }catch(Exception e){
  24. System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement