在java中添加mongod“where”子句

时间:2015-10-06 20:52:06

标签: java mongodb

final Object[] columnNames=new String[] {"Room No.","Room Type","Bed Type","Tariff"};
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); 
DefaultTableModel dtm=new DefaultTableModel(columnNames,0);
dt1=jDateChooser1.getDate();
dt2=jDateChooser2.getDate();
String strdtver1=(String) sdf.format(jDateChooser1.getDate());
String strdtver2=(String) sdf.format(jDateChooser2.getDate());
long diff=((dt2.getTime()-dt1.getTime()+ONE_HOUR)/(ONE_HOUR*24));
diffday=Long.toString(diff);
daytext.setText(diffday+"  day(s)");

roomtable.setRowSelectionAllowed(true);
DefaultTableModel u = (DefaultTableModel) roomtable.getModel();
int n = u.getRowCount();
for (int i = 0;i<n;i++){
    u.removeRow(0);
}
try{
    // JOptionPane.showMessageDialog(null, "Please Enter Mobile Number Correct... ");
    Mongo mongo =new Mongo("127.0.0.1",27017); 
    DB db=mongo.getDB("hotel_management");
    DBCollection collection=db.getCollection("roominfo_info");
    System.out.println("Connected to DB");
    //String day = jComboBox5.getSelectedItem().toString();
    DBCursor cursor = collection.find();
    //DefaultTableModel u = (DefaultTableModel) jTable10.getModel();
    //JOptionPane.showMessageDialog(null, "Please Enter Mobile Number Correct... ");
    while(cursor.hasNext()) {
        u.addRow(new Object[]{
                cursor.next().get("Room No"),
                cursor.curr().get("Room Type"),
                cursor.curr().get("Bed Type"),
                cursor.curr().get("Tariff")
        });                 
    }
} catch (Exception ex) {
    System.out.println(""+ ex);
}    

所以基本上,我在String strdtver1和String strdtver2中存储了日期 我必须使用像我们在mysql中使用的子句,使用where子句,“从”字符串strdtver1“到”字符串strdtver2,以便显示未在该特定时间轴中预订的房间,只有我必须在MongoDB中执行! 谢谢

0 个答案:

没有答案