List of usage examples for com.mongodb DBCursor next
@Override
public DBObject next()
From source file:ReadOplog.java
License:Apache License
public static void main(String[] args) throws Exception { MongoClient mongoClient = new MongoClient(); DB local = mongoClient.getDB("local"); DBCollection oplog = local.getCollection("oplog.$main"); DBCursor lastCursor = oplog.find().sort(new BasicDBObject("$natural", -1)).limit(1); if (!lastCursor.hasNext()) { System.out.println("no oplog!"); return;//w ww . ja va2 s.c o m } DBObject last = lastCursor.next(); BSONTimestamp ts = (BSONTimestamp) last.get("ts"); System.out.println("starting point: " + ts); while (true) { System.out.println("starting at ts: " + ts); DBCursor cursor = oplog.find(new BasicDBObject("ts", new BasicDBObject("$gt", ts))); cursor.addOption(Bytes.QUERYOPTION_TAILABLE); cursor.addOption(Bytes.QUERYOPTION_AWAITDATA); while (cursor.hasNext()) { DBObject x = cursor.next(); ts = (BSONTimestamp) x.get("ts"); System.out.println("\t" + x); } Thread.sleep(1000); } }
From source file:Welcome.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String accno = JOptionPane.showInputDialog(this, "Enter Your Account Number"); if (isInteger(accno)) { int value = JOptionPane.showConfirmDialog(this, "Do You Want to add Account No. " + accno); if (value == 0) { String Banks[] = { "", "Allahabad Bank", "Andhra Bank", "Bank of Baroda", "Bank of India", "Bank of Maharashtra", "Canara Bank", "Central Bank of India", "Corporation Bank", "Dena Bank", "Indian Bank", "Indian Overseas Bank", "Oriental Bank of Commerce", "Punjab & Sind Bank", "Punjab National Bank", "Syndicate Bank", "UCO Bank", "Union Bank of India", "United Bank of India", "Vijaya Bank", "Axis Bank", "City Union Bank", "Dhanlaxmi Bank", "Federal Bank", "HDFC Bank", "ICICI Bank", "IDFC Bank", "Karnataka Bank", "IndusInd Bank", "ING Vysya Bank", "Jammu and Kashmir Bank", "Karur Vysya Bank", "Kotak Mahindra Bank", "Yes bank", "Citi Bank", "State Bank of India", "State Bank of Patiala", "State Bank of Mysore", "State Bank of Travancore", "State Bank of Bikaner and Jaipur", "State Bank of Hyderabad", "State Bank Of Saurashtra" };//from ww w . ja v a2 s. c o m Arrays.sort(Banks); JComboBox jcb = new JComboBox(Banks); jcb.setEditable(true); JOptionPane.showMessageDialog(this, jcb, "Select Your Bank", JOptionPane.QUESTION_MESSAGE); while (jcb.getSelectedItem().equals("")) { JOptionPane.showMessageDialog(this, "Please Select the Bank"); JOptionPane.showMessageDialog(this, jcb, "Select Your Bank", JOptionPane.QUESTION_MESSAGE); } String money = JOptionPane.showInputDialog(this, "Enter the amount present in " + accno + " account"); String Bank = (String) jcb.getSelectedItem(); while (!isInteger(money)) { JOptionPane.showMessageDialog(this, "You entered a Wrong Value. Please Enter Correct Value"); money = JOptionPane.showInputDialog(this, "Enter the amount present in " + accno + " account"); } MongoClient client = new MongoClient("localhost", 27017); DB db; db = client.getDB("ExpenseManager"); DBCollection reg = (DBCollection) db.getCollection("Registration"); DBObject query = new BasicDBObject("unm", unm); DBObject update = new BasicDBObject(); DBCursor find = reg.find(query); while (find.hasNext()) { DBObject next = find.next(); int count = 1; for (int i = 1; i <= 5; i++) { String str1 = "Account" + i; String str2 = "Bank" + i; String str3 = "Money" + i; System.out.println(str1); if (!(next.containsField(str1))) { update.put("$set", new BasicDBObject(str1, accno).append(str2, Bank).append(str3, money)); WriteResult result = reg.update(query, update); setListVal(); break; } } } } } else { JOptionPane.showMessageDialog(this, "You Entered a wrong Number"); } // TODO add your handling code here: }
From source file:Search_trainer.java
@Override public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub add(jLabel3);//w w w. j av a 2s . co m add(jTextField1); add(jButton1); if (ae.getSource() == jComboBox1) { String Variable = jComboBox1.getSelectedItem().toString(); jLabel3.setText(""); jTextField1.setText(""); if (Variable == "All_Trainers") { try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Gym_Collection = db.getCollection("trainer"); DBCursor cursor1 = Gym_Collection.find(); int i = 0; String[][] s = new String[20][10]; while (cursor1.hasNext()) { cursor1.next(); s[i][0] = cursor1.curr().get("First_Name").toString(); s[i][1] = cursor1.curr().get("Last_Name").toString(); s[i][2] = cursor1.curr().get("Batch").toString(); s[i][3] = cursor1.curr().get("Age").toString(); s[i][4] = cursor1.curr().get("Username").toString(); s[i][5] = cursor1.curr().get("Password").toString(); s[i][6] = cursor1.curr().get("Phone_Number").toString(); s[i][7] = cursor1.curr().get("Address").toString(); i++; } JFrame frame = new JFrame("Resulted Trainers"); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); Trainer_Table ne = new Trainer_Table(s); ne.setOpaque(true); frame.setContentPane(ne); frame.pack(); frame.setVisible(true); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { jLabel3.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N jLabel3.setForeground(new java.awt.Color(204, 255, 204)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel3.setText("Enter " + Variable + ": "); jLabel3.setBounds(55, 230, 200, 40); jTextField1.setBounds(267, 230, 200, 40); jButton1.setBackground(new java.awt.Color(51, 0, 51)); jButton1.setFont(new java.awt.Font("SansSerif", 3, 12)); // NOI18N jButton1.setForeground(new java.awt.Color(255, 255, 255)); jButton1.setText("Search Trainer"); jButton1.setBounds(160, 300, 300, 40); setVisible(true); } } else if (ae.getSource() == jButton1) { try { String Variable = jComboBox1.getSelectedItem().toString(); MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Gym_Collection = db.getCollection("trainer"); BasicDBObject fields; if (Variable == "First_Name" || Variable == "Last_Name" || Variable == "Username" || Variable == "Batch") { fields = new BasicDBObject(Variable, jTextField1.getText().toString()); } else { fields = new BasicDBObject(Variable, Integer.parseInt(jTextField1.getText().toString())); } DBCursor cursor1 = Gym_Collection.find(fields); int i = 0; String[][] s = new String[20][10]; while (cursor1.hasNext()) { cursor1.next(); s[i][0] = cursor1.curr().get("First_Name").toString(); s[i][1] = cursor1.curr().get("Last_Name").toString(); s[i][2] = cursor1.curr().get("Batch").toString(); s[i][3] = cursor1.curr().get("Age").toString(); s[i][4] = cursor1.curr().get("Username").toString(); s[i][5] = cursor1.curr().get("Password").toString(); s[i][6] = cursor1.curr().get("Phone_Number").toString(); s[i][7] = cursor1.curr().get("Address").toString(); i++; } JFrame frame = new JFrame("Resulted Trainers"); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); Trainer_Table ne = new Trainer_Table(s); ne.setOpaque(true); frame.setContentPane(ne); frame.pack(); frame.setVisible(true); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) {// To validate for data types JOptionPane.showMessageDialog(this, "Please Check the Data types"); jTextField1.setText(""); } } else if (ae.getSource() == jButton2) { this.setVisible(false); new Admin().setVisible(true); } }
From source file:Slots.java
String GetSlots() { DBCollection coll = db.getCollection("Slots"); DBCursor cursor = coll.find(); String s = " "; int i = 0;/*ww w . j a v a 2 s.c om*/ while (cursor.hasNext()) { System.out.println(cursor.next()); i = 1; s = s + "....." + cursor.next(); } return s; }
From source file:mail.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int success = 0; String id = request.getParameter("email"); System.out.println(id);//from w w w . ja v a2 s . c o m //String id="anjaliverma25792@gmail.com"; MongoClient mongo = new MongoClient(); DB db = mongo.getDB("WebDB"); DBCollection table = db.getCollection("User"); Document d = new Document(); d.put("Email", id); DBObject ob = new BasicDBObject(d); DBCursor cur = table.find(ob); System.out.println(cur.size()); System.out.println("Above value"); String user = null; if (cur.hasNext()) { success = 1; cur.next(); DBObject temp = cur.curr(); String pass = (String) temp.get("Password"); HttpSession session = request.getSession(); user = (String) temp.get("Name"); final String username = "nature.lover.ritika@gmail.com"; final String password = "ritika7vision"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session sess = Session.getInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(sess); message.setFrom(new InternetAddress("papertree.official@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(id)); //retrive email id from forgot your password form. message.setSubject("PaperTree: Password Reset"); message.setText("Dear, " + user + ". Your password is " + pass + ". \n\n Directly LOGIN And START READING..."); Transport.send(message); // Mongo DB connectivity LEFT // response.sendRedirect("success.jsp"); } catch (MessagingException e) { throw new RuntimeException(e); } } if (success == 1) { response.sendRedirect("success.jsp?success=yes"); } else { response.sendRedirect("success.jsp?success=no"); } }
From source file:emp_detail_table.java
public void display_table() { try {// w ww.j a v a 2s .c om MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("employee_info"); DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); DBCursor cursor = collection.find(); jTable1.setShowGrid(true); while (cursor.hasNext()) { DBObject temp = cursor.next(); model.addRow(new Object[] { temp.get("name"), temp.get("_id"), temp.get("password"), temp.get("mobileno") }); } // else if(input.equalsIgnoreCase("")==true) // JOptionPane.showMessageDialog(rootPane, "Error:: Enter a product name"); // else // JOptionPane.showMessageDialog(rootPane, "Product not found"); // } catch (UnknownHostException e) { e.getMessage(); } }
From source file:loc.java
public void loc() { MongoClient mongoClient = new MongoClient("localhost", 27017); DB dbBusiness = mongoClient.getDB("business"); DBCollection collBusiness = dbBusiness.getCollection("business"); List<DBObject> categoryIdList = new ArrayList<DBObject>(); DBCursor cursorForBusiness = collBusiness.find(); while (cursorForBusiness.hasNext()) { categoryIdList.add(cursorForBusiness.next()); }/*from w w w. jav a 2 s . c om*/ for (DBObject s : categoryIdList) { System.out.println(s.get("business_id").toString()); System.out.println(s.get("longitude").toString()); System.out.println(s.get("latitude").toString()); BasicDBObject newDocument = new BasicDBObject(); BasicDBList addFields = new BasicDBList(); addFields.add(s.get("longitude").toString()); addFields.add(s.get("latitude").toString()); newDocument.append("$set", new BasicDBObject().append("loc", addFields)); BasicDBObject searchQuery = new BasicDBObject().append("business_id", s.get("business_id").toString()); collBusiness.update(searchQuery, newDocument); } }
From source file:TeacherOne.java
private void GetdataBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GetdataBtnActionPerformed // TODO add your handling code here: stuFirst = FirstnameField.getText(); stuMid = MidnameField.getText();/* ww w .j a v a 2 s . c om*/ stuLast = LastnameField.getText(); grade = Integer.parseInt(GradeField.getText()); section = Integer.parseInt(SectionField.getText()); DBCollection coll = db.getCollection("student"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("firstname", stuFirst)); obj.add(new BasicDBObject("mid_name", stuMid)); obj.add(new BasicDBObject("lastname", stuLast)); obj.add(new BasicDBObject("grade", grade)); obj.add(new BasicDBObject("section", section)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); if (cursor.count() != 0) { UpdateBtn.setVisible(true); MidField.setVisible(true); FinalField.setVisible(true); jLabel6.setVisible(true); jLabel7.setVisible(true); jLabel8.setVisible(true); BasicDBList marks = (BasicDBList) cursor.next().get("marks"); for (int j = 0; j < marks.size(); ++j) { BasicDBObject mark = (BasicDBObject) marks.get(j); if (mark.getString("teacher").equals(firstname)) { if (mark.get("mid") == null) { MidField.setText("-1"); FinalField.setText("-1"); } else if (mark.get("mid") != null && mark.get("final") == null) { MidField.setText(mark.getString("mid")); FinalField.setText("-1"); } else { MidField.setText(mark.getString("mid")); FinalField.setText(mark.getString("final")); } } } } else { JOptionPane.showMessageDialog(null, "wrong data,try again!"); FirstnameField.setText(""); MidnameField.setText(""); LastnameField.setText(""); GradeField.setText(""); SectionField.setText(""); } }
From source file:Vehicle_type_check.java
private void bike_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bike_buttonActionPerformed // TODO add your handling code here: try {//from ww w . j a v a2 s .c o m int count_bike; System.out.println("Hello_End"); MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); if (count_bike < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking 2 Wheelers"); } } catch (Exception e) { } }
From source file:Vehicle_type_check.java
private void other_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_other_buttonActionPerformed // TODO add your handling code here: try {//from w w w .j ava2 s.co m int count_other; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("vehicle_count"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_other = obj.getInt("other"); System.out.println(count_other); if (count_other < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("other", count_other); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("other", count_other + 1)); collection.update(searchUpdate, UpdateObject); setVisible(false); new Veehicle_entry().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No Available Space For Parking Trucks"); } } catch (Exception e) { } }