Example usage for com.mongodb MongoClient MongoClient

List of usage examples for com.mongodb MongoClient MongoClient

Introduction

In this page you can find the example usage for com.mongodb MongoClient MongoClient.

Prototype

public MongoClient() 

Source Link

Document

Creates an instance based on a (single) mongodb node (localhost, default port).

Usage

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

public void InsertMongo() {
    client = new MongoClient();
    db = client.getDatabase("FinalDemo");
    MongoCollection col = db.getCollection("ItemDetail");
    System.out.println("colection created " + col.toString());
    final Document seedData = createSeedData();
    col.insertOne(seedData);// w w w.  ja  va 2s .  c  o m
    SKUTextField.clear();
    DescriptionTextField.clear();
    ItemNameText.clear();

}

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

private static void createTable(/*Section subCatPart*/String tableName, Paragraph preface)
        throws BadElementException {
    try {/*from w  w w. j  av  a 2 s. co m*/
        ArrayList<String> list = new ArrayList<String>();

        // t.setBorderColor(BaseColor.GRAY);
        // t.setPadding(4);
        // t.setSpacing(4);
        // t.setBorderWidth(1);
        int length = 0;
        java.sql.Connection conn = Connection.getConnect();
        Statement st = conn.createStatement();
        st = conn.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);

        ResultSetMetaData rsMetaData = rs.getMetaData();

        int numberOfColumns = rsMetaData.getColumnCount();
        System.out.println("resultSet MetaData column Count=" + numberOfColumns);
        for (int i = 1; i <= numberOfColumns; i++) {
            length = i;
        }
        MongoClient client = new MongoClient();
        MongoDatabase db = client.getDatabase("FinalDemo");

        PdfPTable table = new PdfPTable(length);

        for (int i = 1; i <= numberOfColumns; i++) {
            // System.out.println("column MetaData ");
            //System.out.println("column number " + i);
            // get the column's name.
            System.out.println(rsMetaData.getColumnName(i));
            PdfPCell c1 = new PdfPCell(new Phrase(rsMetaData.getColumnName(i)));
            c1.setHorizontalAlignment(Element.ALIGN_CENTER);
            list.add(rsMetaData.getColumnName(i));
            table.addCell(c1);
        }
        while (rs.next()) {
            for (String col : list) {
                //System.out.println("Column name is "+col+"value is "+rs.getString(col));
                table.addCell(rs.getString(col));
            }
        }
        /*PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
                
        c1 = new PdfPCell(new Phrase("Table Header 2"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
                
        c1 = new PdfPCell(new Phrase("Table Header 3"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);*/
        table.setHeaderRows(1);

        preface.add(table);
        //subCatPart.add(table);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(VirtualkeyController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(VirtualkeyController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.mycompany.models.Assistente.java

public Assistente() {
    this.produtos = new ArrayList<>();
    this.morphia = new Morphia();
    morphia.mapPackage("com.mycompany.models");
    datastore = morphia.createDatastore(new MongoClient(), "IdealProduto");
    datastore.ensureIndexes();/*from   ww  w  . ja  v a  2  s . c o m*/
}

From source file:com.mycompany.models.Assistente.java

public Assistente(ArrayList<Produto> produtos) {
    this.produtos = produtos;
    this.morphia = new Morphia();
    morphia.mapPackage("com.mycompany.models");
    datastore = morphia.createDatastore(new MongoClient(), "IdealProduto");
    datastore.ensureIndexes();/* w  w w  .  jav  a 2s. co  m*/
}

From source file:com.mycompany.models.Correio.java

public Correio() {
    this.morphia = new Morphia();
    morphia.mapPackage("com.mycompany.models");
    datastore = morphia.createDatastore(new MongoClient(), "Agenda_de_Contatos");
    datastore.ensureIndexes();//from w  w w. j a v a 2 s  .  com
}

From source file:com.mycompany.models.Correio.java

public Correio(Agenda agenda) {

    this.morphia = new Morphia();
    morphia.mapPackage("com.mycompany.models");
    datastore = morphia.createDatastore(new MongoClient(), "Agenda_de_Contatos");
    datastore.ensureIndexes();//  ww w  .ja  va  2  s.c om

    this.agenda = agenda;
}