Example usage for com.mongodb.client MongoCursor hasNext

List of usage examples for com.mongodb.client MongoCursor hasNext

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor hasNext.

Prototype

@Override
    boolean hasNext();

Source Link

Usage

From source file:com.mycompany.mavenproject2.AddDeptController.java

@FXML
public void handleSaveButtonAction(ActionEvent a)
        throws SQLException, ClassNotFoundException, ParseException, IOException {
    System.out.println("You clicked me!");
    // DBCursor cursor = col.find();
    // int i=1;/*www .  jav  a  2s.c  o  m*/
    /*while (cursor.hasNext()) { 
    System.out.println("Inserted Document: "+i); 
    System.out.println(cursor.next()); 
    i++;
    }*/

    /* Iterator<DBObject> fields = cursor.iterator(); 
    while(fields.hasNext()){ //
    BasicDBList geoList = (BasicDBList) fields.next().get("Name");
    BasicDBObject object = (BasicDBObject) geoList.get(0); // this should return {"5": "Continent_Name"}
    Object value = object.get("Name"); // value should contain "Continent_Name"
        System.out.println("Colum name value is "+value);
    }*/
    /* String qry1="select name from dept_detail";
    conn=Connection.getConnect();            
    PreparedStatement pst1=conn.prepareStatement(qry1);
    ResultSet rs1 = pst1.executeQuery(qry1);
    while(rs1.next()){
      if(DeptName.getText().equals(rs1.getString("name"))){
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Department already exist!");
        alert.showAndWait();
        LocalName.clear();
        DeptName.clear();
        value.clear();
        repeat=1;
        break;
      }               
    }  */

    //MongoCursor<Document> myDoc2 =  col.find(eq("Name",DeptName.getText())).iterator();            
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(DeptName.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = col.find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Department already exist!");
        alert.showAndWait();
        LocalName.clear();
        DeptName.clear();
        value.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }
}

From source file:com.mycompany.mavenproject2.AddDeptController.java

public void InsertMongo() throws ParseException, IOException {
    if (Margin.isSelected()) {
        rFlag1 = 1;/*from  w ww  .jav a  2s.  co m*/
    } else {
        rFlag1 = 0;
    }
    if (MarkUp.isSelected()) {
        rFlag2 = 1;
    } else {
        rFlag2 = 0;
    }
    if (Taxable.isSelected()) {
        tFlag = 1;
    } else {
        tFlag = 0;
    }
    if (Price.isSelected()) {
        pFlag = 1;
    } else {
        pFlag = 0;
    }
    if (FoodStamp.isSelected()) {
        fFlag = 1;
    } else {
        fFlag = 0;
    }

    /* DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
     db.getCollection("restaurants").insertOne(  new Document("address",
                 new Document()
                         .append("street", "2 Avenue")
                         .append("zipcode", "10075")
                         .append("building", "1480")
                         .append("coord", asList(-73.9557413, 40.7720266)))
                 .append("borough", "Manhattan")
                 .append("cuisine", "Italian")
                 .append("grades", asList(
                         new Document()
                                 .append("date", format.parse("2014-10-01T00:00:00Z"))
                                 .append("grade", "A")
                                 .append("score", 11),
                         new Document()
                                 .append("date", format.parse("2014-01-16T00:00:00Z"))
                                 .append("grade", "B")
                                 .append("score", 17)))
                 .append("name", "Vella")
                 .append("restaurant_id", "41704620"));
     System.out.println("Data are Inserted");*/
    //Find all document
    /*b=new BasicDBObject();
    b.put("Name", "sdfg");
    MongoCursor<Document> cursor = db.getCollection("CategoryDetail").find(b).iterator();
    try {
    while (cursor.hasNext()) {
        System.out.println("Searched Output "+cursor.next().toJson() );
                
    }
    } finally {
    cursor.close();
    }*/
    /* MongoCursor<Document> cursor4 = db.getCollection("CategoryDetail").find().iterator();
      try {
    while (cursor4.hasNext()) {
        System.out.println("column val is "+cursor4.next().getString("LocalName"));
                
    }
     } finally {
    cursor.close();
     }*/
    //Find First Document

    /*   Document myDoc = db.getCollection("restaurants").find().first();
       System.out.println("First Column is "+myDoc.toJson());*/
    //Where Clause
    /*Document myDoc = db.getCollection("restaurants").find(eq("borough", "ManhattanFirst")).first();
    System.out.println("sd" +myDoc.toJson());*/
    //col.find({}).sort({_id:-1}).limit(1);
    count = (int) col.count();
    if (count == 0) {
        seedData = createSeedData();
        col.insertOne(seedData);
    } else {
        sort1 = new BasicDBObject();
        MongoCursor<Document> cursor = col.find().sort(sort1).limit(1).skip((int) count - 1).iterator();
        try {
            while (cursor.hasNext()) {
                ID = cursor.next().getInteger("ID");
                System.out.println("last ID " + ID);
                ID++;
                System.out.println("Inserted " + ID);
            }
        } finally {
            cursor.close();
        }
        final Document seedData = createSeedData();
        col.insertOne(seedData);

    }
    /*count= (long) col.count();
    MongoCursor<Document> cursor = col.find().sort(sort1).limit(1).skip((int)count-1).iterator();        
    try {
    while (cursor.hasNext()) {
        System.out.println("Searched Output "+cursor.next().toJson());
    }
    } finally {
    cursor.close();
    }*/

    /* MongoCursor<Document> cursor = col.find().limit(3).sort({timestamp:-1}); 
     try {
    while (cursor.hasNext()) {
        System.out.println("Searched Output "+cursor.next().toJson());
    }
     } finally {
    cursor.close();
     }*/
    Stage stage = new Stage();
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/SelectDept.fxml"));
    Parent root4 = (Parent) fxmlLoader.load();
    SelectDeptController controller = fxmlLoader.<SelectDeptController>getController();
    stage.setScene(new Scene(root4));
    stage.setTitle("Select Department");
    controller.update();
    LocalName.clear();
    DeptName.clear();
    value.clear();
}

From source file:com.mycompany.mavenproject2.AddDeptController.java

@FXML
public void handleSaveCloseButtonAction(ActionEvent e) throws ParseException {

    /* t1.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
    @Override//from   w  w  w.  j av a  2  s . co m
    public void changed(ObservableValue<? extends Toggle> ov, Toggle t, Toggle t1) {
            
    RadioButton chk = (RadioButton)t1.getToggleGroup().getSelectedToggle(); // Cast object to radio button
    System.out.println("Selected Radio Button - "+chk.getText());
            
    }
    });*/

    /*java.sql.Connection conn=Connection.getConnect();
    String Add1="INSERT INTO dept_detail " 
            +"(`name`,`local_name`,taxable,foodStamp,Price,margin,markup,value) "
            + "VALUES (?,?,?,?,?,?,?,?)";          
    PreparedStatement ReceiptQuery=conn.prepareStatement(Add1);
    ReceiptQuery.setString(1, DeptName.getText().toString());
    ReceiptQuery.setString(2, LocalName.getText().toString());
    ReceiptQuery.setInt(3, tFlag);
    ReceiptQuery.setInt(4, fFlag);
    ReceiptQuery.setInt(5, pFlag);
    ReceiptQuery.setInt(6, rFlag1);
    ReceiptQuery.setInt(7, rFlag2);
    ReceiptQuery.setString(8, value.getText().toString());       
    ReceiptQuery.executeUpdate();*/
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(DeptName.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = col.find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Department already exist!");
        alert.showAndWait();
        LocalName.clear();
        DeptName.clear();
        value.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        try {
            InsertMongo();
            // InsertSQl(conn);
        } catch (IOException ex) {
            Logger.getLogger(AddDeptController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    Stage stage = (Stage) Save.getScene().getWindow();
    stage.close();
}

From source file:com.mycompany.mavenproject2.AddGroupController.java

public void EditButton(String Name) {
    obv.removeAll(obv);//from   w  w  w  .j  ava2s. c om
    grp = Name;
    GroupNameText.setText(Name);
    ItemTable2.getItems().removeAll(obv);
    GroupNameText.setDisable(true);
    System.out.println("Cllaed " + Name);
    GlobalFlag = 1;
    db1.put("GroupName", Name);
    MongoCursor<Document> cursorFind = db.getCollection("ItemGroup").find(db1).iterator();
    MongoCursor<Document> cursorFind1 = db.getCollection("ItemDetail").find().iterator();
    while (cursorFind.hasNext()) {
        Document g = cursorFind.next();
        GroupDescText.setText(g.getString("GroupDesc"));
        Document d = (Document) g.get("Items");
        while (cursorFind1.hasNext()) {
            Document g1 = cursorFind1.next();
            if (d.getString(g1.getString("SKU")) != null) {

                obv.add(new Person(g1.getString("SKU"), g1.getString("ItemDesc"), g1.getString("Size_Name"),
                        g1.getString("Pack_Name"), g1.getString("UnitPrice")));
                ItemTable2.setItems(obv);
            }
        }

    }
}

From source file:com.mycompany.mavenproject2.AddGroupController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    skucol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("SKU"));
    desc.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Desc"));
    size.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Size"));
    pack.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Pack"));
    price.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Price"));
    sku.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("SKU"));
    desccol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Desc"));
    sizecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Size"));
    packcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Pack"));
    pricecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Price"));
    data.removeAll(data);//w w w .  j  av  a  2 s  .com
    ItemTable.getItems().removeAll(data);
    MongoCursor<Document> cursorFind = db.getCollection("ItemDetail").find().iterator();
    while (cursorFind.hasNext()) {
        Document g = cursorFind.next();
        data.add(new Person(g.getString("SKU"), g.getString("ItemDesc"), g.getString("Size_Name"),
                g.getString("Pack_Name"), g.getString("UnitCost")));
    }
    ItemTable.setItems(data);
    /*  MongoCursor<Document> cur = db.getCollection("CategoryDetail").find().iterator();
      CatCombo.getItems().clear();
    try {
    while (cur.hasNext()) {                
        String rs1=cur.next().getString("Name");              
        CatCombo.setValue(rs1);
        CatCombo.getItems().addAll(rs1);           
    }             
      } finally {
    cur.close();
      }   
      cur =  db.getCollection("DeptDetail").find().iterator();
    try {
    while (cur.hasNext()) {                
        String rs=cur.next().getString("Name");
        DeptCombo.setValue(rs);
        DeptCombo.getItems().addAll(rs);                
    }
      } finally {
    cur.close();
      }     
     cur =  db.getCollection("BrandDetail").find().iterator();
    try {
    while (cur.hasNext()) {                
        String rs=cur.next().getString("Name");
        BrandCombo.setValue(rs);
        BrandCombo.getItems().addAll(rs);                
    }
      } finally {
    cur.close();
      }   
      cur =  db.getCollection("PackDetail").find().iterator();
    try {
        while (cur.hasNext()) {                
        String rs=cur.next().getString("Name");
        PackCombo.setValue(rs);
        PackCombo.getItems().addAll(rs);                
    }
      } finally {
    cur.close();
      }   
      cur =  db.getCollection("SizeDetail").find().iterator();
    try {
    while (cur.hasNext()) {                
        String rs=cur.next().getString("Name");
        SizeCombo.setValue(rs);
        SizeCombo.getItems().addAll(rs);                
    }
      } finally {
    cur.close();
      }*/
    filterField.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {

            //updateFilteredData();
            initFilter();
        }
    });
}

From source file:com.mycompany.mavenproject2.AddItemListController.java

@FXML
public void handleSaveitemButtonAction(ActionEvent a) {
    //sku,description,item name,combo(brand,location,dept,size,cat,pack),
    //model no.,part no.,check(inactive item,non plu,non stock item,prompt for quality,prompt for price)
    table.getItems().forEach(item -> System.out.println("fetched quanity is " + item.getValue()));
    ref = new BasicDBObject();
    ref.put("ItemName", Pattern.compile(UnitText.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = db.getCollection("ItemDetailDetail").find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Item Name Already exist!");
        alert.showAndWait();// w  ww  .j a v a2s .c o m

        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }
}

From source file:com.mycompany.mavenproject2.AddItemListController.java

public Document createSeedData() {
    d = new Document();
    b = new BasicDBObject();
    b.put("Name", DeptCombo.getValue());
    MongoCursor<Document> cursor = db.getCollection("DeptDetail").find(b).iterator();
    try {//from www  .j  av a  2s  . c  o m
        while (cursor.hasNext()) {
            dept_id = cursor.next().getInteger("ID");
            System.out.println("Searched Output " + dept_id);
        }
    } finally {
        cursor.close();
    }

    b.clear();
    b.put("Name", SizeCombo.getValue().toString());
    System.out.println("Size outtput is " + SizeCombo.getValue().toString());
    cursor = db.getCollection("SizeDetail").find(b).iterator();
    try {
        while (cursor.hasNext()) {
            size_name = cursor.next().getString("Name");
            System.out.println("size Output " + size_name);

        }
    } finally {
        cursor.close();
    }
    b.clear();
    b.put("Name", PackCombo.getValue().toString());
    cursor = db.getCollection("PackDetail").find(b).iterator();
    try {
        while (cursor.hasNext()) {
            pack_name = cursor.next().getString("Name");
            System.out.println("pack Output " + pack_name);
        }
    } finally {
        cursor.close();
    }
    b.clear();
    b.put("Name", BrandCombo.getValue().toString());
    cursor = db.getCollection("BrandDetail").find(b).iterator();
    try {
        while (cursor.hasNext()) {
            brand_name = cursor.next().getString("Name");
            System.out.println("brand Output " + brand_name);
        }
    } finally {
        cursor.close();
    }
    if (NonStockCheck.isSelected()) {
        nonstock = 1;
    } else {
        nonstock = 0;
    }
    if (NonTaxCheck.isSelected()) {
        nontax = 1;
    } else {
        nontax = 0;
    }
    if (QuantityCheck.isSelected()) {
        qua = 1;
    } else {
        qua = 0;
    }
    if (PriceCheck.isSelected()) {
        priceF = 1;
    } else {
        priceF = 0;
    }
    if (WeightedItem.isSelected()) {
        check1 = 1;
    } else {
        check1 = 0;
    }
    if (WebItem.isSelected()) {
        check2 = 1;
    } else {
        check2 = 0;
    }
    if (ExcludeSale.isSelected()) {
        check3 = 1;
    } else {
        check3 = 0;
    }
    if (WIC.isSelected()) {
        check4 = 1;
    } else {
        check4 = 0;
    }
    if (HealthCard.isSelected()) {
        check5 = 1;
    } else {
        check5 = 0;
    }
    if (FoodStamp.isSelected()) {
        check6 = 1;
    } else {
        check6 = 0;
    }
    if (NonRevenueItem.isSelected()) {
        check7 = 1;
    } else {
        check7 = 0;
    }
    if (NonDiscountable.isSelected()) {
        check8 = 1;
    } else {
        check8 = 0;
    }

    d.append("SKU", SKUTextField.getText());
    d.append("ItemDesc", DescriptionTextField.getText());
    d.append("ItemName", ItemNameText.getText());
    d.append("Dept_ID", dept_id);
    d.append("Size_Name", size_name);
    d.append("Pack_Name", pack_name);
    d.append("Cat_Name", CatCombo.getValue());
    d.append("Brand_Name", brand_name);
    d.append("Location", LocationCombo.getValue());
    d.append("Model_Num", ModelText.getText());
    d.append("Part_Num", PartText.getText());
    d.append("NonStock", nonstock);
    d.append("UnitType", IventoryTypeCombo.getValue());
    d.append("NonText", nontax);
    d.append("Tax1", Tax1Text.getText());
    d.append("Tax2", Tax2Text.getText());
    d.append("Tax3", Tax3Text.getText());
    d.append("QualityPrompt", priceF);
    d.append("PricePrompt", priceF);
    d.append("UnitCost", UnitCostText.getText());
    d.append("UnitPrice", UnitPriceText.getText());
    d.append("Margin", MarginText.getText());
    d.append("MSRP", MSRPText.getText());
    d.append("BuyDownAmount", BuyDownText.getText());
    d.append("MarkUP", MarkUpText.getText());
    d.append("SalesPrice", SaleText.getText());
    d.append("WeightedItem", check1);
    d.append("WebItem", check2);
    d.append("ExcludeSale", check3);
    d.append("WIC", check4);
    d.append("HealthCard", check5);
    d.append("FoodStamp", check6);
    d.append("NonRevenueItem", check7);
    d.append("NonDiscountable", check8);
    table.getItems().forEach(item -> d.append("Quantity", item.getValue()));
    costTable.getItems().forEach(item -> d.append("CostQuantity", item.getUnitName()));
    costTable.getItems().forEach(item -> d.append("Price", item.getValue()));
    return d;
}

From source file:com.mycompany.mavenproject2.AddItemListController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    // quantitycol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("Value"));
    /*worked facilitycol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("UnitName"));
            //from   w w  w.j  a  v  a  2  s. c o m
    quantitycol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
      table.setEditable(true);                
    table.setItems(data);*/
    // quantitycol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("Value"));
    table.setEditable(true);

    Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = (
            TableColumn<Person, String> p) -> new EditCell3();

    facilitycol.setCellValueFactory(
            new javafx.scene.control.cell.PropertyValueFactory<Person, String>("UnitName"));

    // quantitycol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
    quantitycol.setCellValueFactory(new PropertyValueFactory<>("Qantity"));
    quantitycol.setCellFactory(cellFactory);
    /* quantitycol.setOnEditCommit((CellEditEvent<Person, String> t) -> {
    ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setValue(t.getNewValue());
     });*/
    table.setItems(data);
    /*table.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent e) {
            
        if( e.getCode() == KeyCode.TAB) { // commit should be performed implicitly via focusedProperty, but isn't
            table.getSelectionModel().selectNext();
            e.consume();
            return;
        }
        else if( e.getCode() == KeyCode.ENTER) { // commit should be performed implicitly via focusedProperty, but isn't
            table.getSelectionModel().selectBelowCell();
            e.consume();
            return;
        }
            
        // switch to edit mode on keypress, but only if we aren't already in edit mode
        if( table.getEditingCell() == null) {
            if( e.getCode().isLetterKey() || e.getCode().isDigitKey()) {  
            
                TablePosition focusedCellPosition = table.getFocusModel().getFocusedCell();
                table.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn());
            
            }
        }
            
    }
       });*/

    quantitycol.setOnEditCommit(new EventHandler<CellEditEvent<Person, String>>() {
        @Override
        public void handle(CellEditEvent<Person, String> t) {
            ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setValue(t.getNewValue());

        }
    });
    // single cell selection mode
    table.getSelectionModel().setCellSelectionEnabled(true);
    table.getSelectionModel().selectFirst();
    DeptCombo.valueProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue ov, String t, String t1) {
            System.out.println("Observation value is " + ov);
            System.out.println("Last selected is " + t);
            System.out.println("current selection " + t1);
            SelctedDept = t1;
            obj.put("Name", SelctedDept);
            MongoCursor<Document> cur = db.getCollection("DeptDetail").find(obj).iterator();
            try {
                while (cur.hasNext()) {
                    int rs = cur.next().getInteger("ID");
                    System.out.println("first Selcted dept is " + SelctedDept + " id is   " + rs);
                    ADept = rs;
                }

            } finally {
                cur.close();
            }
            obj1.put("Dept_ID", ADept);
            cur = db.getCollection("CategoryDetail").find(obj1).iterator();
            CatCombo.getItems().clear();
            try {
                while (cur.hasNext()) {
                    String rs1 = cur.next().getString("Name");
                    System.out.println("Category for dept is " + SelctedDept + " Category is   " + rs1);

                    CatCombo.setValue(rs1);
                    CatCombo.getItems().addAll(rs1);
                }

            } finally {
                cur.close();
            }
        }
    });

    /*       String qry="select name from category_detail";
    String qry1="select name from dept_detail";
    String qry4="select name from size_detail";
    String qry5="select name from pack_detail";
    String qry6="select name from brand_detail";
    String qry7="select name from location_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    PreparedStatement pst1=conn.prepareStatement(qry1);
    PreparedStatement pst4=conn.prepareStatement(qry4);
    PreparedStatement pst5=conn.prepareStatement(qry5);
    PreparedStatement pst6=conn.prepareStatement(qry6);
    PreparedStatement pst7=conn.prepareStatement(qry7);
    ResultSet rs = pst2.executeQuery(qry);
    ResultSet rs1 = pst1.executeQuery(qry1);
    ResultSet rs4 = pst4.executeQuery(qry4);            
    ResultSet rs5 = pst5.executeQuery(qry5);            
    ResultSet rs6 = pst6.executeQuery(qry6);            
    ResultSet rs7 = pst7.executeQuery(qry7);            
    while(rs.next()){
      CatCombo.setValue(rs.getString("name"));
      CatCombo.getItems().addAll(rs.getString("name"));
    }            
          while(rs1.next()){
     DeptCombo.setValue(rs1.getString("name"));
     DeptCombo.getItems().addAll(rs1.getString("name"));
    }
          while(rs4.next()){
     SizeCombo.setValue(rs4.getString("name"));
     SizeCombo.getItems().addAll(rs4.getString("name"));
    }
          while(rs5.next()){
     PackCombo.setValue(rs5.getString("name"));
     PackCombo.getItems().addAll(rs5.getString("name"));
    }
          while(rs6.next()){
     BrandCombo.setValue(rs6.getString("name"));
     BrandCombo.getItems().addAll(rs6.getString("name"));
    }
          while(rs7.next()){
     LocationCombo.setValue(rs7.getString("name"));
     LocationCombo.getItems().addAll(rs7.getString("name"));
    }*/
    MongoCursor<Document> cursor4 = db.getCollection("CategoryDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            CatCombo.setValue(rs);
            CatCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("DeptDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            DeptCombo.setValue(rs);
            DeptCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("LocationDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            LocationCombo.setValue(rs);
            LocationCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("BrandDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            BrandCombo.setValue(rs);
            BrandCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("PackDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            PackCombo.setValue(rs);
            PackCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("SizeDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            SizeCombo.setValue(rs);
            SizeCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}

From source file:com.mycompany.mavenproject2.AddLocationController.java

@FXML
public void handleSaveNewButton(ActionEvent a) {
    /*  java.sql.Connection conn=Connection.getConnect();
    String Add1="INSERT INTO location_detail(`name`)VALUES ?)";          
    PreparedStatement inQuery=conn.prepareStatement(Add1);
    inQuery.setString(1, AreaName.getText().toString());           
    inQuery.executeUpdate();/* w w  w .jav  a2  s  . c  o  m*/
    AreaName.clear();           */
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(AreaName.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = col.find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Area already exist!");
        alert.showAndWait();
        AreaName.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }
}

From source file:com.mycompany.mavenproject2.AddLocationController.java

@FXML
public void handleSaveCloseButtonAction(ActionEvent a) {
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(AreaName.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = col.find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Area already exist!");
        alert.showAndWait();//from   w  w w  . j  a  v a2  s . c  om
        AreaName.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }

    Stage stage = (Stage) Save.getScene().getWindow();
    stage.close();
}