List of usage examples for com.mongodb MongoClient MongoClient
public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoDriverInformation)
From source file:emp_detail_table.java
public void display_table() { try {//from ww w. java2s . com 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 ww w .ja va 2 s . c o m*/ 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:MenuDefCateg.java
public static void getCategories() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Category"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) CategTextArea.append(s + "\n"); }/*from w ww .j a v a2 s .c o m*/ }
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 {/*w w w . java 2 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 {/*w ww .ja v a 2 s .c o 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) { } }
From source file:Vehicle_type_check.java
private void car_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_car_buttonActionPerformed // TODO add your handling code here: try {/*ww w . j a v a 2 s . com*/ int count_car; 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_4", 1); DBCursor cursor = collection.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); if (count_car < 50) { BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_4", count_car); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_4", count_car + 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:MenuIS.java
public static void getIS() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("derivProb", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results.limit(1)) { List<String> conv = (List<String>) doc.get("initialState"); {//ww w. ja v a2 s . co m for (String s : conv) ISTextArea.append(s + "\n"); } } }
From source file:AddRecord.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: int flag = 0; try {// w w w . j a v a 2 s. co m // TODO add your handling code here: MongoClient mongoClient = new MongoClient("localhost", 27017); db = mongoClient.getDB("Classic_Hangman"); System.out.println("Connected to database successfully!!"); BasicDBObject d = new BasicDBObject(); String movie = jTextField1.getText(); //String genre = jTextField2.getText(); String director = jTextField3.getText(); for (int i = 0; i < director.length(); i++) { if (Character.isDigit(director.charAt(i))) { JOptionPane.showMessageDialog(this, "Invalid director entry!"); flag = 1; break; } } if (movie.equals("") || genre.equals("")) { JOptionPane.showMessageDialog(this, "Empty Field!"); } else { if (flag != 1) { DBCollection coll = db.getCollection("movies"); DBCollection coll1 = db.getCollection("counter"); System.out.println("Collection selected successfully"); BasicDBObject query = new BasicDBObject(); DBObject c = coll1.findOne(); count = ((Number) c.get("count")).intValue(); System.out.println("Count = " + count); //count = (int)c.get("count"); BasicDBObject doc = new BasicDBObject("id", count + 1).append("name", movie) .append("director", director).append("genre", genre); coll.insert(doc); System.out.println("Document inserted successfully"); count++; /*DBCursor cursor = coll.find(); int i=1; while (cursor.hasNext()) { System.out.println("Inserted Document: "+i); System.out.println(cursor.next()); i++; }*/ //DBCollection coll1 = db.getCollection("counter"); //System.out.println("Collection selected successfully"); coll1.remove(new BasicDBObject()); BasicDBObject doc1 = new BasicDBObject("count", count); coll1.insert(doc1); /*cursor = coll.find(); BasicDBObject newDocument = new BasicDBObject(); System.out.println(count); newDocument.put("count", count); BasicDBObject searchQuery = new BasicDBObject().append("count", count); coll.update(searchQuery, newDocument);*/ jTextField1.setText(""); //jTextField2.setText(""); jTextField3.setText(""); JOptionPane.showMessageDialog(this, "Record added!"); } } } catch (UnknownHostException ex) { //Logger.getLogger(AdminLogin.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Credits.java
Credits() { mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases db = mongoClient.getDB("test"); }
From source file:Register.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: MongoClient client = new MongoClient("localhost", 27017); MongoDatabase db = client.getDatabase("ExpenseManager"); MongoCollection<Document> reg = db.getCollection("Registration"); String unm = jTextField2.getText(); BasicDBObject query = new BasicDBObject("unm", unm); String pass = String.valueOf(jPasswordField1.getPassword()); String c_pass = String.valueOf(jPasswordField2.getPassword()); if (unm.length() == 0) { JOptionPane.showMessageDialog(null, "User Name is empty"); this.setVisible(true); }//from w ww . jav a2 s . c o m else if (reg.find(query).iterator().hasNext()) { JOptionPane.showMessageDialog(null, "User Name already exist"); this.setVisible(true); } else if (jPasswordField1.getPassword().length == 0 || jPasswordField2.getPassword().length == 0) { JOptionPane.showMessageDialog(null, "Password Field Can not be empty"); this.setVisible(true); } else if (!pass.equals(c_pass)) { JOptionPane.showMessageDialog(null, "Passwords do not match. Please Re-enter the password"); this.setVisible(true); } else { String name = jTextField1.getText(); Document ins = new Document("name", name).append("unm", unm).append("pass", pass); reg.insertOne(ins); System.out.println("Document is inserted into MongoDb"); System.out.println(pass); db.createCollection(unm); this.dispose(); login lgn = new login(); lgn.setVisible(true); } }