Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // TODO Auto-generated method stub
- String name = request.getParameter("age");
- boolean submitButtonPressed = request.getParameter("submit") != null;
- System.out.print(name);
- try{
- System.out.print(name);
- // To connect to mongodb server
- MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
- // Now connect to your databases
- DB db = mongoClient.getDB( "local" );
- DBCollection coll = db.getCollection("Employee");
- BasicDBObject gtQuery = new BasicDBObject();
- gtQuery.put("Age", new BasicDBObject("$gt", name).append("$lt", 50));
- DBCursor cursor = coll.find(gtQuery);
- int i=1;
- while (cursor.hasNext())
- {
- System.out.println("Inserted Document: "+i);
- System.out.println(cursor.next());
- i++;
- }
- }catch(Exception e){
- System.err.println( e.getClass().getName() + ": " + e.getMessage() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement