Example usage for com.mongodb DBObject get

List of usage examples for com.mongodb DBObject get

Introduction

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

Prototype

Object get(String key);

Source Link

Document

Gets a field from this object by a given name.

Usage

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  ww.  j  av a  2 s  . c o 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:Highscores.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {/*from ww  w  . j av  a 2 s . c om*/
        String user;
        int count = 1;
        String highscore;
        jTextArea2.append("SR No.\tUSERNAME\tHIGHSCORE\n");
        int high;
        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("Classic_Hangman");
        System.out.println("Connected to database successfully!!");
        DBCollection coll = db.getCollection("high_score");
        System.out.println("Collection Retrieved");
        DBCursor cursor = coll.find();
        cursor.sort(new BasicDBObject("value", -1));
        while (cursor.hasNext() && count < 4) {
            DBObject result = cursor.next();
            high = ((Number) result.get("value")).intValue();
            highscore = Integer.toString(high);
            user = (String) result.get("_id");
            jTextArea2.append(count + "\t" + user + "\t" + highscore + "\n");
            count++;
        }
    } catch (UnknownHostException ex) {
        Logger.getLogger(Highscores.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:login_page.java

private void LoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoginActionPerformed
    // TODO add your handling code here:
    try {//from   www.  j a  va  2  s.  co m
        int check = 0;
        userid = UserID.getText();
        password = Password.getText();
        submit = Login.getActionCommand();

        if (radio_check == -99)
            JOptionPane.showMessageDialog(null, "Please Chhose Admin/Employee");
        else {
            if (radio_check == 0) {
                if ((userid.equals("admin")) && (password.equals("password123"))) {
                    System.out.println("Done");

                    //TO connect theses two pages..
                    setVisible(false);
                    new Admin_rights().setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Invalid Admin Login");
                }
            } else {
                MongoClient mc = new MongoClient("localhost", 27017);
                DB db = mc.getDB("parking_system");
                DBCollection collection = db.getCollection("employee_info");
                /*ISERT DOCUMENT 
                BasicDBObject doc = new BasicDBObject("userid",userid).append("password",password);
                collection.insert(doc);
                */
                DBCursor cursor = collection.find();
                DBObject obj;

                String temp_user, temp_pass;

                while (cursor.hasNext()) {
                    obj = (DBObject) cursor.next();

                    temp_user = obj.get("_id").toString();
                    temp_pass = obj.get("password").toString();

                    if ((userid.equals(temp_user)) && (password.equals(temp_pass))) {
                        System.out.println("Done");

                        //TO connect theses two pages..
                        setVisible(false);
                        /*new Vehicle_type_check().setVisible(true);*/
                        new Entry_OR_Exit().setVisible(true);
                        check = 1;
                        break;
                    }
                }
                if (check != 1) {
                    JOptionPane.showMessageDialog(null, "Authentication Failed!\nInvalid Login");
                }
            }
        }
    } catch (Exception e) {

    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadAset(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Kode", "Golongan", "Posisi", "Keterangan" }, 0) {
        @Override/*from  ww w  .  j  a  v  a 2s  .  com*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblAset.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("rekening").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Rekening re = new achmad.rifai.erp1.entity.Rekening(json);
        if (re.isDeleted())
            m.addRow(new Object[] { re.getKode(), re.getGolongan(), re.getPosisi(), re.getKet() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadIncome(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "KODE", "Tanggal", "Jurnal", "Jumlah" }, 0) {
        @Override/*from   www .  ja v a2 s . com*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblIncome.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("terima").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Terima t = new achmad.rifai.erp1.entity.Terima(json);
        if (t.isDeleted())
            m.addRow(new Object[] { t.getKode(), t.getTgl(), t.getJurnal(), t.getUang() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadPembelian(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "STRUK", "SUPLIER", "TANGGAL", "UANG YANG DIKELUARKAN" }, 0) {
        @Override//from   ww w  . j a  va  2 s  .c  o m
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblPembelian.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("pembelian").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Pembelian p = new achmad.rifai.erp1.entity.Pembelian(json);
        if (p.isDeleted())
            m.addRow(new Object[] { p.getStruk(), p.getSuplier(), p.getTgl(), p.getHarga() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadPenjualan(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Nota", "Pelanggan", "Tanggal", "Total", "UANG YANG DIBAYAR", "Keterangan" }, 0) {
        @Override/*from ww  w . j ava2  s  .  c o  m*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblPenjualan.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("penjualan").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Penjualan p = new achmad.rifai.erp1.entity.Penjualan(json);
        if (p.isDeleted())
            m.addRow(new Object[] { p.getNota(), p.getPelanggan(), p.getTgl(), p.getTotal(), p.getTerbayar(),
                    p.getKet() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadPesan(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Kode", "Isi Pesan", "Pengirim", "Waktu" }, 0) {
        @Override/*from   ww  w  .  j a va2s  . co m*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblPesan.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("pesan").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Pesan p = new achmad.rifai.erp1.entity.Pesan(json);
        if (p.isDeleted())
            m.addRow(new Object[] { p.getKode(), p.getPesan(), p.getPengirim(), p.getWaktu() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadSuplier(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Kode", "Nama" }, 0) {
        @Override/*from w  w w.  ja v a  2s . com*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblSuplier.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("suplier").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Suplier s = new achmad.rifai.erp1.entity.Suplier(json);
        if (s.isDeleted())
            m.addRow(new Object[] { s.getKode(), s.getNama() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadPerilaku(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Kode", "Pelaku", "Bulan", "Tahun" }, 0) {
        @Override//from  w w  w  .j a va  2s  .com
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblPerilaku.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("tracks").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Tracks t = new achmad.rifai.erp1.entity.Tracks(json);
        if (t.isDeleted())
            m.addRow(new Object[] { t.getKode(), t.getId(), t.getBln(), t.getTahun() });
    }
}