populate value from mongo db in java

hi i have gui which get value from mongo db how can i populate value this is my gui
Capturetab12.PNGsomething like this
hi how can I search value from database using combobox for example I enter username and return the detail of that username something like this
import javax.swing.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;//where do I get this am getting error is not recognise
import java.awt.*;

public class Demo {

    JFrame frame = new JFrame("");
    AutoCompleteDecorator decorator;
    JComboBox combobox;

    public Demo() {
        combobox = new JComboBox(new Object[]{"","Ester", "Jordi",
            "Jordina", "Jorge", "Sergi"});//I what to searc from database
        AutoCompleteDecorator.decorate(combobox);
        frame.setSize(400,400);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());

        frame.add(combobox);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        Demo d = new Demo();
    }
}

Open in new window

chalie001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sachiekCommented:
Not sure if you are looking to populate like 100s of document?

Here is this example you can see simple insert..
http://www.journaldev.com/3963/mongodb-java-crud-example-tutorial

https://github.com/mongolab/mongodb-driver-examples/blob/master/java/JavaSimpleExample.java
0
gurpsbassiCommented:
@chalie001 your question makes no sense.
Is this a follow up from the previous question I helped you with?

@TomasHelgi in your previous post already gave you some pointers about implementing a listener on your combo box. Did you make an effort to read it?
0
chalie001Author Commented:
yes is a follow up
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

gurpsbassiCommented:
Please answer second question:

@TomasHelgi in your previous post already gave you some pointers about implementing a listener on your combo box. Did you make an effort to read it?
0
chalie001Author Commented:
yes i  did this is my gui
public class CreateUserGUI extends JFrame{

    private static final long serialVersionUID = 1L;
	private JPanel backgroundPanel = null, backPanel = null, topPanel = null, bottomPanel = null, sidePanel = null;
	private JTextField txtName = null, txtSurname = null, txtUsername = null;
	private JPasswordField passwordField = null;
	private JLabel nameLabel = null, surnameLabel = null, usernameLabel = null, passwordLabel = null, statusComboLabel = null,sUsernameLabale =null;
	private JButton btnSave = null, btnCancel = null, btnCreate = null, btnUpdate = null, btnDelete = null, btnSearch = null,uBtnSave = null,dUpdate = null;
	private JComboBox<String> usernameCombo = null;
	private JLabel sSurnameLabel = null,sPasswordLabel = null,SName = null;
	private JTextField sTxtname = null,sTxtSurname = null;
	private JPasswordField sTxtPassword  = null;
    private JComboBox<String> Uusernamecombo = null;
	private JLabel uUsername = null,Unamelabel = null,uSurname = null ,uPasswordLabel = null,DusernameLabel = null,DstatusLabel =null;
	private JPasswordField Upassword = null;
	private JTextField txtUname = null,txtUSurname = null,txtUsurname = null; 
	private JComboBox<String> Dusername = null,DustatusCombo = null;	
	
	
	
	
	public CreateUserGUI()
	{
		
	//	backPanel = new JPanel(new GridBagLayout());
			backPanel = new JPanel(new  BorderLayout());
	//	topPanel = new JPanel(new GridBagLayout());
		JTabbedPane jtp = new JTabbedPane();
		getContentPane().add(jtp);
		
		
		
    	JPanel jp1 = new JPanel();
        JPanel jp2 = new JPanel();
        JPanel jp3 = new JPanel();
        JPanel jp4 = new JPanel();
		
		JLabel label1 = new JLabel();
        label1.setText("You are in area of creating new User");
        JLabel label2 = new JLabel();
        nameLabel = new JLabel("Name : ");
	    txtName = new JTextField(15);
		txtName.setMinimumSize(txtName.getPreferredSize());   	
	    surnameLabel = new JLabel("Surname : ");
	    txtSurname = new JTextField(15);
	    txtSurname.setMinimumSize(txtSurname.getPreferredSize());
	    usernameLabel = new JLabel("Username : ");
	    txtUsername = new JTextField(15);
	    txtUsername.setMinimumSize(	txtUsername.getPreferredSize());
	    passwordLabel = new JLabel("Password : ");
	    passwordField = new  JPasswordField(15);
	    passwordField.setMinimumSize(passwordField.getPreferredSize());
	    btnSave = new JButton("Save") {
	        {
	            setSize(5, 8);
	            setMinimumSize(getSize());
	        }
	    };        
	    	
	  btnCreate = new JButton("Create"){
	  {
	  	setSize(5,8);
	  	setMinimumSize(getSize());
	  }
	  };  	
	    	
       // label1.setBounds(5,15,100,20);
        nameLabel.setBounds(1, 50, 150, 20);
	   	txtName.setBounds(70,50,150,20);
		surnameLabel.setBounds(1, 80, 150, 20);
		txtSurname.setBounds(70,80,150,20);
		usernameLabel.setBounds(1,110,150,20);
		txtUsername.setBounds(70,110,150,20);
		passwordLabel.setBounds(1, 140, 150, 20);
		passwordField.setBounds(70, 140, 150, 20);  
		btnSave.setBounds(70,160,80,20);	
		btnCreate.setBounds(140,160,80,20);	
        

        
        label2.setText("You are in area of Updating user Information");
      //  JLabel label3 = new JLabel();
        uUsername = new JLabel("Username");
        Uusernamecombo = new JComboBox<>();
        Unamelabel = new JLabel("Name");
        txtUname = new JTextField(15);
        txtUname.setMinimumSize(txtUname.getPreferredSize());
        uSurname = new JLabel("Surname");
        txtUSurname = new JTextField(15);
        txtUSurname.setMinimumSize(txtUSurname.getPreferredSize());
        uPasswordLabel = new JLabel("Password");
        Upassword = new JPasswordField(15);
        Upassword.setMinimumSize(Upassword.getPreferredSize());
        uBtnSave = new JButton("Save") {
	        {
	            setSize(5, 8);
	            //setMaximumSize(getSize());
	            setMinimumSize(getSize());
	        }
	    };        
        
        uUsername.setBounds(1,30,100,20);
		Uusernamecombo.setBounds(90,30,150,20);
		Unamelabel.setBounds(1,70,100,20);
		txtUname.setBounds(90,70,150,20);
		uSurname.setBounds(1,90,150,20);
		txtUSurname.setBounds(90,90,150,20);
		uPasswordLabel.setBounds(1,110,150,20);
		Upassword.setBounds(90,110,150,20);
		uBtnSave.setBounds(100,140,80,20);
		
   
        
//        label3.setText("You are in area of seting  user Inactive");
        DusernameLabel  = new JLabel("Username");
        Dusername = new JComboBox<>();
        DstatusLabel= new JLabel("Status");
        DustatusCombo = new JComboBox<>();
        DustatusCombo.addItem("Active");
		DustatusCombo.addItem("Inactive");
        dUpdate = new JButton("Save"){
        {
        	setSize(5, 8);
	            
	        setMinimumSize(getSize());
        }
        }; 
        	
       DusernameLabel.setBounds(1,30,150,20);
       Dusername.setBounds(70,30,150,20);
       DstatusLabel.setBounds(1,70,100,20) ;	
       DustatusCombo.setBounds(70,70,150,20);
       dUpdate.setBounds(100,140,80,20);
        
     
        
        
        
        JLabel label4 = new JLabel();
        label4.setText("username ");
        sUsernameLabale = new JLabel("Username : ");
		usernameCombo = new JComboBox<>();
		//statusCombo.addItem("Active");
	//	statusCombo.addItem("Inactive");
		SName = new JLabel("Name");
		sTxtname = new JTextField(15);
		sTxtname.setMinimumSize(sTxtname.getPreferredSize()); 
		sSurnameLabel = new JLabel("Surname");
		sTxtSurname = new JTextField(15);
		sTxtSurname.setMinimumSize(sTxtSurname.getPreferredSize());
		sPasswordLabel = new JLabel("Password");
		sTxtPassword = new JPasswordField(15);
		sTxtPassword.setMinimumSize(sTxtPassword.getPreferredSize());
		
	
		
		label4.setBounds(1,30,150,20);
		usernameCombo.setBounds(90,30,150,20);
		SName.setBounds(1,70,100,20);
		sTxtname.setBounds(90,70,150,20);
		sSurnameLabel.setBounds(1,90,150,20);
		sTxtSurname.setBounds(90,90,150,20);
		sPasswordLabel.setBounds(1,110,150,20);
		sTxtPassword.setBounds(90,110,150,20);
		
		
		
		/*txtName = new JTextField();
		txtSurname = new JTextField();
		txtUsername = new JTextField();
		passwordField = new JPasswordField();
		
		
		nameLabel = new JLabel("Name : ");
		surnameLabel = new JLabel("Surname : ");
		usernameLabel = new JLabel("Username : ");
		passwordLabel = new JLabel("Password : ");*/
		//****statusComboLabel = new JLabel("Status : ");
		
		
   	//topPanel.setLayout(null);
   //	bottomPanel.setLayout(new GridLayout(0,1));
		
		
    /*  topPanel.add(nameLabel);
      topPanel.add(txtName);
      topPanel.add(surnameLabel);
      topPanel.add(txtSurname);
      topPanel.add(passwordLabel);
      topPanel.add(passwordField);*/
      
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridLayout(2,2));
      
        jp1.setLayout(null);
        jp1.add(label1);
        jp1.add(nameLabel);
        jp1.add(txtName);
        jp1.add(usernameLabel);
        jp1.add(txtUsername);
        jp1.add(surnameLabel);
        jp1.add(txtSurname);
        jp1.add(passwordLabel);
        jp1.add(passwordField);
        jp1.add(btnSave);
        jp1.add(btnCreate);
        
        jp2.setLayout(null);
        jp2.add(uUsername);
        jp2.add(Uusernamecombo);
        jp2.add(Unamelabel);
        jp2.add(txtUname);
        jp2.add(uSurname);
        jp2.add(txtUSurname);
        jp2.add(uPasswordLabel);
        jp2.add(Upassword);
        jp2.add(uBtnSave);
        
        
        
        //DstatusLabel.setBounds(1,70,100,20) ;	
       //DustatusCombo.setStatus(90,70,150,20);
        
       
        jp3.setLayout(null);
       // jp3.add(label3);
        jp3.add(DusernameLabel);
        jp3.add(Dusername);
        jp3.add(DstatusLabel);
        jp3.add(DustatusCombo);
        jp3.add(dUpdate);
        jp4.setLayout(null);
        jp4.add(label4);
        jp4.add(usernameCombo);
        jp4.add(SName);
        jp4.add(sTxtname);
        jp4.add(sSurnameLabel);
        jp4.add(sTxtSurname);
        jp4.add(sPasswordLabel);
        jp4.add(sTxtPassword);
        
        
        
        jtp.addTab("create", jp1);
        jtp.addTab("update", jp2);
        jtp.addTab("Delete", jp3);
        jtp.addTab("Search", jp4);
		
	
		
	this.setTitle("Create User");
    this.setSize(600,450);
    this.setLocation(500, 280);
		
		
	Toolkit toolkit = getToolkit();
		
		Dimension size = toolkit.getScreenSize();
		
		setLocation(size.width/2 - getWidth()/2,
				size.height/2 - getHeight()/2);		
		
		
		
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.getContentPane().add(topPanel);
		
this.setVisible(true);
		
	}

Open in new window


i what to know how can i implement
import javax.swing.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;//where do I get this am getting error is not recognise
import java.awt.*;

public class Demo {

    JFrame frame = new JFrame("");
    AutoCompleteDecorator decorator;
    JComboBox combobox;

    public Demo() {
        combobox = new JComboBox(new Object[]{"","Ester", "Jordi",
            "Jordina", "Jorge", "Sergi"});//I what to searc from database
        AutoCompleteDecorator.decorate(combobox);
        frame.setSize(400,400);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());

        frame.add(combobox);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        Demo d = new Demo();
    }
}

Open in new window

0
chalie001Author Commented:
the sample is using had code value
 String[] items = { "item1", "item2" };
    JComboBox cb = new JComboBox(items);
    cb.setEditable(true);

    MyItemListener actionListener = new MyItemListener();
    cb.addItemListener(actionListener);

i what to list value from database
0
gurpsbassiCommented:
Why haven't you added a listener to the combo box?
0
chalie001Author Commented:
am tring to do this
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


ItemListener itemListener = new ItemListener();


but am geting error cannot instanitiate the type ItemListener
0
chalie001Author Commented:
must i create this inside my clas
class MyItemListener implements ItemListener {
  // This method is called only if a new item has been selected.
  public void itemStateChanged(ItemEvent evt) {
    JComboBox cb = (JComboBox) evt.getSource();

    Object item = evt.getItem();

    if (evt.getStateChange() == ItemEvent.SELECTED) {
      // Item was just selected
    } else if (evt.getStateChange() == ItemEvent.DESELECTED) {
      // Item is no longer selected
    }
  }
0
CEHJCommented:
but am geting error cannot instanitiate the type ItemListener
You can't instantiate an interface. I would either main the main enclosing class implement it
combobox.addItemListener(this);

Open in new window

, or make a private (named) inner class

But the gui doesn't make sense either. The person searching should not know usernames and definitely not passwords
0
gurpsbassiCommented:
ItemListener itemListener = new ItemListener();
 needs to be

ItemListener itemListener = new MyItemListener();
0
chalie001Author Commented:
am having MyItemListener() cannot be resolve
0
chalie001Author Commented:
ok i created class
class MyItemListener implements ItemListener {
  // This method is called only if a new item has been selected.
  public void itemStateChanged(ItemEvent evt) {
    JComboBox cb = (JComboBox) evt.getSource();

    Object item = evt.getItem();

    if (evt.getStateChange() == ItemEvent.SELECTED) {
      // Item was just selected
    } else if (evt.getStateChange() == ItemEvent.DESELECTED) {
      // Item is no longer selected
    }
  }

Open in new window


and what next
0
CEHJCommented:
You haven't told us how this is meant to work so how can we know?
0
chalie001Author Commented:
ok in the combo box the the mus select the username or type the username and populate the username details name surname the password will be ************
0
chalie001Author Commented:
i also need AutoCompleteDecorator.decorate(combobox in combo box
0
chalie001Author Commented:
what happen is there is a login screen where the adim person will login by entering username and password and come to the create user screen the screen got option to create new user to update current user information and to inactivated the user
0
CEHJCommented:
ok in the combo box the the mus select the username

OK, that suggests that the combo is pre-filled. That would be done (otherwise it would be pointless to do it at all) by a query for all usernames. It's conceivable that if you're going to do that, it should retrieve first and last names too. NOT password - which should be encrypted (so it would be useless to see it anyway)
0
chalie001Author Commented:
this is the process
loginthe createuser tab
createsearchdelete
0
chalie001Author Commented:
in the update tab the admin can update the password the combobox can be prefilled if possible be able to enter username
0
gurpsbassiCommented:
MyItemListener needs to be public. Unless you've got it as an inner class somewhere.
0
CEHJCommented:
You need to write the code that fills the combo first. If you use
JComboBox<User>

Open in new window

and fill it with User data objects, you can use those objects to fill in the first and last name form fields too
0
chalie001Author Commented:
how do i get ther user from database and fill it in combobox
0
chalie001Author Commented:
you mean private JComboBox<User> tUser = null;
0
CEHJCommented:
how do i get ther user from database and fill it in combobox
I don't use mongodb. You'll need to check the tutorials

you mean private JComboBox<User> tUser = null;
Something like that, but why would you use a name like 'tUser'? It tells you nothing about what it is or does.
0
gurpsbassiCommented:
how do i get ther user from database and fill it in combobox

I've already given you the code to fetch the user from DB.
You need to use the object returned now.
0
CEHJCommented:
I've already given you the code to fetch the user from DB.
Sorry to bother you, but for the rest of us, a link could be useful
0
gurpsbassiCommented:
0
CEHJCommented:
Thanks. OK, so this one. Will there be such a collection pre-existing btw?
0
gurpsbassiCommented:
I believe @chalie001 has already got the database collection from the screen shot I saw in the previous post of the mongo database viewing tool.
0
chalie001Author Commented:
hi i did this i created a class public class MyItemListener implements ItemListener
i did this

private JComboBox<String> Uusernamecombo = null;
ItemListener itemListener = new MyItemListener();
  Uusernamecombo  = new JComboBox<>();
 Uusernamecombo.setBounds(90,30,150,20);
jp4.add(Uusernamecombo);
now i what to add listner to my combobox
Uusernamecombo.addActionListener(itemListener);
am geting this error
error
0
gurpsbassiCommented:
use addItemListener not addActionListener
0
CEHJCommented:
private JComboBox<String> Uusernamecombo = null;

Open in new window

So you decided to ignore my advice. That will just give you more problems later

Also, your naming is wrong, see
http://technojeeves.com/index.php/aliasjava1/106-java-style-conventions
0
chalie001Author Commented:
i did this
private JComboBox<User> Uusernamecombo = null;
 Uusernamecombo.addItemListener(itemListener);

the combobox is still empty
0
chalie001Author Commented:
i did not ignore your advice will put proper name when am done
0
CEHJCommented:
i did this
private JComboBox<User> Uusernamecombo = null;

Open in new window


So, you created a User class presumably? If so, please post it
0
chalie001Author Commented:
no which class is that
0
CEHJCommented:
So how can your claim HERE be true? The code would not have compiled
0
chalie001Author Commented:
am not suppose to do something like this
import javax.swing.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;//where do I get this am getting error is not recognise
import java.awt.*;

public class Demo {

    JFrame frame = new JFrame("");
    AutoCompleteDecorator decorator;
    JComboBox combobox;

    public Demo() {
        combobox = new JComboBox(new Object[]{"","Ester", "Jordi",
            "Jordina", "Jorge", "Sergi"});//I what to searc from database
        AutoCompleteDecorator.decorate(combobox);
        frame.setSize(400,400);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());

        frame.add(combobox);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        Demo d = new Demo();
    }
}

Open in new window

Make DBObject  return either an array or list of Strings for populating the combobox, then look at ComboBoxModel
0
chalie001Author Commented:
this is my code
public class CreateUserGUI extends JFrame implements ActionListener{

	private static final long serialVersionUID = 1L;
	private JPanel backgroundPanel = null, backPanel = null, topPanel = null, bottomPanel = null, sidePanel = null;
	private JTextField txtName = null, txtSurname = null, txtUsername = null;
	private JPasswordField passwordField = null;
	private JLabel nameLabel = null, surnameLabel = null, usernameLabel = null, passwordLabel = null, statusComboLabel = null,sUsernameLabale =null;
	private JButton btnSave = null, btnCancel = null, btnCreate = null, btnUpdate = null, btnDelete = null, btnSearch = null,uBtnSave = null,dUpdate = null;
	private JComboBox<String> statusCombo = null;
	private JComboBox<User> Uusernamecombo = null;
	//private JLabel uUsername = null,Unamelabel = null,uSurname = null ,uPasswordLabel = null;
	private JLabel sSurnameLabel = null,sPasswordLabel = null,SName = null;
	private JTextField sTxtname = null,sTxtSurname = null;
	private JPasswordField Upassword = null;
	private JPasswordField sTxtPassword  = null;
	//private JTextField txtUname = null,txtUSurname = null,txtUsurname = null; 
	//private JComboBox<String> Uusernamecombo = null;
	private JComboBox<User> usernameCombo = null;
	private JLabel uUsername = null,Unamelabel = null,uSurname = null ,uPasswordLabel = null,DusernameLabel = null,DstatusLabel =null;
	//private JPasswordField Upassword = null;
	private JTextField txtUname = null,txtUSurname = null,txtUsurname = null; 
	private JComboBox<User> Dusername = null;
	private JComboBox<String> DustatusCombo = null;	
	//private JComboBox<String> Dusername = null,DustatusCombo = null;
	private JComboBox<User> tUser = null;
	//
	
	  ItemListener itemListener = new MyItemListener();
	//ItemListener itemListener = new ItemListener();
	
	private User user = null;
	private UserDAO dao = null;
	private ArrayList<User> users = null;
	private LogFile log = null;
	
	
	
	public CreateUserGUI()
	{
		
	//	backPanel = new JPanel(new GridBagLayout());
			backPanel = new JPanel(new  BorderLayout());
	//	topPanel = new JPanel(new GridBagLayout());
		JTabbedPane jtp = new JTabbedPane();
		getContentPane().add(jtp);
		
		
		
    	JPanel jp1 = new JPanel();
        JPanel jp2 = new JPanel();
        JPanel jp3 = new JPanel();
        JPanel jp4 = new JPanel();
		
		JLabel label1 = new JLabel();
        label1.setText("You are in area of creating new User");
        JLabel label2 = new JLabel();
        nameLabel = new JLabel("Name : ");
	    txtName = new JTextField(15);
		txtName.setMinimumSize(txtName.getPreferredSize());   	
	    surnameLabel = new JLabel("Surname : ");
	    txtSurname = new JTextField(15);
	    txtSurname.setMinimumSize(txtSurname.getPreferredSize());
	    usernameLabel = new JLabel("Username : ");
	    txtUsername = new JTextField(15);
	    txtUsername.setMinimumSize(	txtUsername.getPreferredSize());
	    passwordLabel = new JLabel("Password : ");
	    passwordField = new  JPasswordField(15);
	    passwordField.setMinimumSize(passwordField.getPreferredSize());
	    btnSave = new JButton("Save") {
	        {
	            setSize(5, 8);
	            setMinimumSize(getSize());
	        }
	    };        
	    	
	  btnCreate = new JButton("Create"){
	  {
	  	setSize(5,8);
	  	setMinimumSize(getSize());
	  }
	  };  	
	    	
       // label1.setBounds(5,15,100,20);
        nameLabel.setBounds(1, 50, 150, 20);
	   	txtName.setBounds(70,50,150,20);
		surnameLabel.setBounds(1, 80, 150, 20);
		txtSurname.setBounds(70,80,150,20);
		usernameLabel.setBounds(1,110,150,20);
		txtUsername.setBounds(70,110,150,20);
		passwordLabel.setBounds(1, 140, 150, 20);
		passwordField.setBounds(70, 140, 150, 20);  
		btnSave.setBounds(70,160,80,20);	
		btnCreate.setBounds(140,160,80,20);	
        

        
        label2.setText("You are in area of Updating user Information");
      //  JLabel label3 = new JLabel();
        uUsername = new JLabel("Username");
        usernameCombo = new JComboBox<>();
        Unamelabel = new JLabel("Name");
        txtUname = new JTextField(15);
        txtUname.setMinimumSize(txtUname.getPreferredSize());
        uSurname = new JLabel("Surname");
        txtUSurname = new JTextField(15);
        txtUSurname.setMinimumSize(txtUSurname.getPreferredSize());
        uPasswordLabel = new JLabel("Password");
        Upassword = new JPasswordField(15);
        Upassword.setMinimumSize(Upassword.getPreferredSize());
        uBtnSave = new JButton("Save") {
	        {
	            setSize(5, 8);
	            //setMaximumSize(getSize());
	            setMinimumSize(getSize());
	        }
	    };        
        
        uUsername.setBounds(1,30,100,20);
        usernameCombo.setBounds(90,30,150,20);
		Unamelabel.setBounds(1,70,100,20);
		txtUname.setBounds(90,70,150,20);
		uSurname.setBounds(1,90,150,20);
		txtUSurname.setBounds(90,90,150,20);
		uPasswordLabel.setBounds(1,110,150,20);
		Upassword.setBounds(90,110,150,20);
		uBtnSave.setBounds(100,140,80,20);
		
   
        
//        label3.setText("You are in area of seting  user Inactive");
        DusernameLabel  = new JLabel("Username");
        Dusername = new JComboBox<>();
        DstatusLabel= new JLabel("Status");
        DustatusCombo = new JComboBox<>();
        DustatusCombo.addItem("Active");
		DustatusCombo.addItem("Inactive");
        dUpdate = new JButton("Save"){
        {
        	setSize(5, 8);
	            
	        setMinimumSize(getSize());
        }
        }; 
        	
       DusernameLabel.setBounds(1,30,150,20);
       Dusername.setBounds(70,30,150,20);
       DstatusLabel.setBounds(1,70,100,20) ;	
       DustatusCombo.setBounds(70,70,150,20);
       dUpdate.setBounds(100,140,80,20);
        
     
        
        
        
        JLabel label4 = new JLabel();
        label4.setText("username ");
        sUsernameLabale = new JLabel("Username : ");
        Uusernamecombo  = new JComboBox<>();
		//statusCombo.addItem("Active");
	//	statusCombo.addItem("Inactive");
		SName = new JLabel("Name");
		sTxtname = new JTextField(15);
		sTxtname.setMinimumSize(sTxtname.getPreferredSize()); 
		sSurnameLabel = new JLabel("Surname");
		sTxtSurname = new JTextField(15);
		sTxtSurname.setMinimumSize(sTxtSurname.getPreferredSize());
		sPasswordLabel = new JLabel("Password");
		sTxtPassword = new JPasswordField(15);
		sTxtPassword.setMinimumSize(sTxtPassword.getPreferredSize());
		
	
		
		label4.setBounds(1,30,150,20);
		 Uusernamecombo.setBounds(90,30,150,20);
		SName.setBounds(1,70,100,20);
		sTxtname.setBounds(90,70,150,20);
		sSurnameLabel.setBounds(1,90,150,20);
		sTxtSurname.setBounds(90,90,150,20);
		sPasswordLabel.setBounds(1,110,150,20);
		sTxtPassword.setBounds(90,110,150,20);
		
		
		
		/*txtName = new JTextField();
		txtSurname = new JTextField();
		txtUsername = new JTextField();
		passwordField = new JPasswordField();
		
		
		nameLabel = new JLabel("Name : ");
		surnameLabel = new JLabel("Surname : ");
		usernameLabel = new JLabel("Username : ");
		passwordLabel = new JLabel("Password : ");*/
		//****statusComboLabel = new JLabel("Status : ");
		
		
   	//topPanel.setLayout(null);
   //	bottomPanel.setLayout(new GridLayout(0,1));
		
		
    /*  topPanel.add(nameLabel);
      topPanel.add(txtName);
      topPanel.add(surnameLabel);
      topPanel.add(txtSurname);
      topPanel.add(passwordLabel);
      topPanel.add(passwordField);*/
      
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridLayout(2,2));
      
        jp1.setLayout(null);
        jp1.add(label1);
        jp1.add(nameLabel);
        jp1.add(txtName);
        jp1.add(usernameLabel);
        jp1.add(txtUsername);
        jp1.add(surnameLabel);
        jp1.add(txtSurname);
        jp1.add(passwordLabel);
        jp1.add(passwordField);
        jp1.add(btnSave);
        jp1.add(btnCreate);
        
        jp2.setLayout(null);
        jp2.add(uUsername);
        jp2.add(usernameCombo);
        jp2.add(Unamelabel);
        jp2.add(txtUname);
        jp2.add(uSurname);
        jp2.add(txtUSurname);
        jp2.add(uPasswordLabel);
        jp2.add(Upassword);
        jp2.add(uBtnSave);
        
        
        
        //DstatusLabel.setBounds(1,70,100,20) ;	
       //DustatusCombo.setStatus(90,70,150,20);
        
       
        jp3.setLayout(null);
       // jp3.add(label3);
        jp3.add(DusernameLabel);
        jp3.add(Dusername);
        jp3.add(DstatusLabel);
        jp3.add(DustatusCombo);
        jp3.add(dUpdate);
        jp4.setLayout(null);
        jp4.add(label4);
        jp4.add(Uusernamecombo);
        jp4.add(SName);
        jp4.add(sTxtname);
        jp4.add(sSurnameLabel);
        jp4.add(sTxtSurname);
        jp4.add(sPasswordLabel);
        jp4.add(sTxtPassword);
        
        
        
        jtp.addTab("create", jp1);
        jtp.addTab("update", jp2);
        jtp.addTab("Delete", jp3);
        jtp.addTab("Search", jp4);
        
        
      
        Uusernamecombo.addItemListener(itemListener);
        usernameCombo.addItemListener(itemListener);
        Dusername.addItemListener(itemListener);
        
        
        
      
        
        
        
		
	
		
	this.setTitle("Create User");
    this.setSize(600,450);
    this.setLocation(500, 280);
		
		
	Toolkit toolkit = getToolkit();
		
		Dimension size = toolkit.getScreenSize();
		
		setLocation(size.width/2 - getWidth()/2,
				size.height/2 - getHeight()/2);		
		
		
		
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.getContentPane().add(topPanel);
		
this.setVisible(true);
		
	}

Open in new window

0
CEHJCommented:
You're wasting my time, so i'm unsubscribing
0
chalie001Author Commented:
sorry
0
gurpsbassiCommented:
@chalie001 I am very confused now.
You seem to have 2  requirements here

1. populating the combo box with initial data

2. upon selecting a value from the combo box, populating the form.

which one are we working on??
0
chalie001Author Commented:
. populating the combo box with initial data
0
chalie001Author Commented:
after that i must be able to
upon selecting a value from the combo box, populating the form

e.g if i selet the username i must populate the  name and surname of that user
0
chalie001Author Commented:
hi any progress
0
gurpsbassiCommented:
First you need to tell me what object you intend to give your view layer? Do you have some kind of model object?
0
chalie001Author Commented:
Sorry what do you mean by model object i ll show you how i did insert but am not happy about it
0
gurpsbassiCommented:
Lets rewind.....I don't care about your inserts.
I am trying to help you with requirement no 1 that is populating the combo box with initial data.

In order to do this you have to :
(a) read from the database through a DAO
(b) return the data in a format that your front end would understand.

Can you tell me which one of these you are having trouble with? and have you made any efforts to help yourself?
0
chalie001Author Commented:
Ok on front end I what to display name and surname of username yes you have to uses Dao
0
chalie001Author Commented:
To read using Dao that's my problem and populate to username to combobox
0
gurpsbassiCommented:
public Map<String, DBObject> findAllUsers(){
  DBCollection dbCollection = mongo.getDB("system").getCollection("users");
  DBCursor cursor = dbCollection.find();
  Map<String, DBObject> allUsers = new HashMap<>();
  while(cursor.hasNext()){
   DBObject dbObj = cursor.next();
   allUsers.put((String)dbObj.get("username"), dbObj);
 }
  return allUsers;
}

Open in new window


Thats the code you need in your DAO to get the all the users in the collection.
0
gurpsbassiCommented:
To populate your combo box:

Map<String, DBObject> allusers = dao.findAllUsers();

for(String key : allUsers.keySet()){
  jComboBox.addItem(key);
}

Open in new window


I've stored the entire BSON object in a Map so when you call your event listener on the jCombo box, it will know the selected value which is a key in the map.

Pull out the relevant BSON object via the key to populate the rest of the fields on the screen. Remember BSON object itself can be treated as a Map. So use get(String) method to get back the value.
0
gurpsbassiCommented:

Map<String, DBObject> allusers = dao.findAllUsers();

for(String key : allUsers.keySet()){
  jComboBox.addItem(key);
}

Open in new window

0
chalie001Author Commented:
must i do like this
 Uusernamecombo.addItemListener(itemListener);
        Map<String, DBObject> allusers = dao.findAllUsers();

        for(User key : allUsers.keySet()){
        	 Uusernamecombo.addItem(key);
        }

Open in new window

where is allUsers define
0
chalie001Author Commented:
am geting this error i did this
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at sita.co.za.gui.CreateUserGUI.<init>(CreateUserGUI.java:340)
      at sita.co.za.gui.LoginGUI.actionPerformed(LoginGUI.java:141)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$500(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)


private JComboBox<String> Uusernamecombo = null;
Uusernamecombo.addItemListener(itemListener);
        Map<String, DBObject> allusers = dao.findAllUsers();

        for(String key : allusers.keySet()){
        	 Uusernamecombo.addItem(key);
        }

Open in new window

0
chalie001Author Commented:
this is my  DAO


import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;



import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoException;

public class UserDAO {

	private ConnectToDB connection = null;
	private DBCollection collection = null;
	private BasicDBObject document = null;
	private BasicDBObject searchQuery = null;
	private DBCursor cursor = null;
	private ArrayList<DBObject> allUsers, newUsers = null;
	private DBObject record = null;
	private BasicDBObject userSets = null, fieldSets = null; 
	private LogFile log = null;
	private ArrayList<User> duplicates = null;
	 
	
	
	public UserDAO() {
		
		connection = new ConnectToDB();
		collection = connection.getDB().getCollection("user");
		document = new BasicDBObject();
		allUsers = new ArrayList<DBObject>();
		log = new LogFile();
		duplicates = new ArrayList<User>();
		newUsers = new ArrayList<DBObject>();
	}
	
	
	public boolean saveUser(User user) throws Exception{
	
		boolean isSaved = false;
		if(isDuplicate(user) && user.getStatus().equals("Active"))
		{
			log.writeToFile("INFO : User already exist in the database. User can not be saved..");
			isSaved = false;
			throw new Exception("User already exist in the database. User can not be saved..");
		}
		else
		{
			document.put("name", user.getName());
			document.put("surname", user.getSurname());
			document.put("username", user.getUsername());
			document.put("password", String.valueOf(user.getPassword()));
			document.put("status", user.getStatus());
			
			try {
				
				collection.insert(document);
				isSaved = true;
				
			} catch (MongoException mongoException){
				
				isSaved = false;
				throw new MongoException(" Something went wrong while attempting to save user...User was not saved ");
			}
		}	
		
		return isSaved;
	}
	
	
	public boolean saveMultipleUsers(ArrayList<User> users) throws FileNotFoundException, IOException, MongoException
	{
		boolean areSaved = false;
		
		for(int z = 0; z < users.size(); z++)
		{
			try {
				try {
					if(isDuplicate(users.get(z)))
					{
						areSaved = false;
					}
					else
					{
						document.put("name", users.get(z).getName());
						document.put("surname", users.get(z).getSurname());
						document.put("username", users.get(z).getUsername());
						document.put("password", String.valueOf(users.get(z).getPassword()));
						document.put("status", users.get(z).getStatus()); 
						
						newUsers.add(document);
						
						document = new BasicDBObject();
					}
				} catch (FileNotFoundException notFound) {
					
					throw new IOException(notFound.getMessage());
					
				}catch (IOException ioException) {
				
					throw new IOException(ioException.getMessage());
					
				} catch (Exception exception) {
					
					throw new IOException(exception.getMessage());
				}
			} catch (Exception e) {
				e.getMessage();
			}
		}
		
		try {

			collection.insert(newUsers);

			log.writeToFile(" Users were successfully saved..");

			areSaved = true;
		}
		catch (MongoException mongoException) {

			areSaved = false;
			log.writeToFile(" ERROR : Something went wrong while attempting to save users to the database..");
			throw new MongoException(" Something went wrong with the database while attempting to save users... Users not saved.");
					} 
		catch (FileNotFoundException notFound) {
			
			areSaved = false;
			throw new FileNotFoundException(notFound.getMessage());
		}
	
		return areSaved;
	}
	
	
	
	
	public boolean searchUser(User user) {

		searchQuery = new BasicDBObject();
		
		if(user != null)
		{
			searchQuery.put("username", user.getUsername());
			cursor = collection.find(searchQuery);
			record = null;
			
			while(cursor.hasNext()) {
				
				record = cursor.next();    
			}
			
			if(record != null)
			{
				user.setName(record.get("name").toString());
				user.setSurname(record.get("surname").toString());
				user.setPassword(record.get("password").toString().toCharArray());
				user.setStatus(record.get("status").toString());
				
				return true;
			}
			else
				return false;
		}
		else
		{
			System.out.println("User does not exist.........");
			return false;
		}
		
	}
	
	public Map<String, DBObject> findAllUsers(){
		 MongoClient mongo = new MongoClient("00.0.0.00", 27017);
		  DBCollection dbCollection = mongo.getDB("dbname").getCollection("users");
		  DBCursor cursor = dbCollection.find();
		  Map<String, DBObject> allUsers = new HashMap<>();
		  while(cursor.hasNext()){
		   DBObject dbObj = cursor.next();
		   allUsers.put((String)dbObj.get("username"), dbObj);
		 }
		  return allUsers;
		}
	
	
	public boolean updateUser(User user) throws FileNotFoundException, MongoException, IOException, Exception
	{	
		boolean isUpdated = false;
		userSets = new BasicDBObject(); 
		fieldSets = new BasicDBObject(); 
		fieldSets.put("name", user.getName()); 
		fieldSets.put("surname", user.getSurname()); 
		fieldSets.put("username", user.getUsername());
		fieldSets.put("password", String.valueOf(user.getPassword()));
		fieldSets.put("status", user.getStatus()); 

		userSets.put( "$set", fieldSets); 
		searchQuery = new BasicDBObject().append("username", user.getUsername());
		
		try
		{			
			collection.update(searchQuery, fieldSets);
			log.writeToFile("INFO : User was successfully updated...");
			isUpdated = true;
		}
		catch(MongoException exception)
		{
			log.writeToFile("ERROR : Something went wrong while trying to update the user...");
			isUpdated = false;
		}
		catch(FileNotFoundException fileNotFound)
		{
			isUpdated = false;
			throw new FileNotFoundException(fileNotFound.getMessage());
		}
		catch(Exception exception)
		{
			isUpdated = false;
			throw new Exception("Something went wrong while trying to update the user...");
		}
		
		return isUpdated;
	}

	
	public boolean deleteUser(User user) throws MongoException, FileNotFoundException, IOException, Exception
	{
		boolean isFound = false;
		
		try {
			
			if(searchUser(user))
			{			
				collection.remove(record);
				log.writeToFile("INFO : User was successfully deleted...");
				isFound = true;
			}
			else
			{
				log.writeToFile("ERROR : User could not be deleted...");
				isFound = false;
			}
			
		} catch (MongoException mongoException) {
			
			isFound = false;
			throw new MongoException(mongoException.getMessage());
			
		}
		catch (FileNotFoundException notFound) {
			
			isFound = false;
			throw new FileNotFoundException(notFound.getMessage());
			
		}catch (IOException ioException) {
			
			isFound = false;
			throw new IOException(ioException.getMessage());
		}
		catch (Exception exception) {
			
			isFound = false;
			throw new Exception(exception.getMessage());
		}
		
		return isFound;
	}
		
	
	public ArrayList<DBObject> findAllusers()
	{
		cursor = collection.find();
		
		while(cursor.hasNext())
		{
			allUsers.add(cursor.next());
		}
		
		return allUsers;		
	}
	
	
	public boolean isDuplicate(User user) throws MongoException, FileNotFoundException, IOException, Exception
	{
		boolean isDuplicate = false;
		int count = findAllusers().size();
		ArrayList<String> usernames = new ArrayList<String>();
		
		for (int x = 0; x < count; x++) {
			
			usernames.add(findAllusers().get(x).get("username").toString());	
			
			if(usernames.get(x).equals(user.getUsername()))
			{				
				try {
					log.writeToFile("WARNING : Duplicate User found in the DB...");
					isDuplicate = true;
					duplicates.add(user);
					
				} catch (FileNotFoundException notFound) {
					
					throw new IOException(notFound.getMessage());
					
				}catch (IOException ioException) {
				
					throw new IOException(ioException.getMessage());
				}
				catch (Exception exception) {
					
					throw new Exception(exception.getMessage());
				}
			}
		}
		
		return isDuplicate;	
	}
	
	
	public ArrayList<User> getDuplicates() {
		return duplicates;
	}


	public DBObject getRecord() {
		return record;
	}
}

Open in new window

0
gurpsbassiCommented:
please. One question at a time!


where is allUsers define

It will need to be a private instance variable perhaps because you will need to refer to it when the combo box changes value upon user interaction.
0
gurpsbassiCommented:
Uusernamecombo

Really bad name for a variable!!!!
0
chalie001Author Commented:
in the dao

private ArrayList<DBObject> allUsers = nul;
allUsers = new ArrayList<DBObject>();
0
chalie001Author Commented:
am geting NPE in this line Map<String, DBObject> allusers = dao.findAllUsers();
0
gurpsbassiCommented:
have you instantiated the dao?
0
chalie001Author Commented:
UserDAO dao = new UserDAO(); am geting this error
      
      Nov 10, 2015 1:20:28 PM com.mongodb.DBTCPConnector$MyPort error
SEVERE: MyPort.error called
java.io.IOException: couldn't connect to [/00.0.0.27:27017] bc:java.net.ConnectException: Connection timed out: connect
      at com.mongodb.DBPort._open(DBPort.java:205)
      at com.mongodb.DBPort.go(DBPort.java:94)
      at com.mongodb.DBPort.go(DBPort.java:75)
      at com.mongodb.DBPort.call(DBPort.java:65)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:215)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:224)
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
      at com.mongodb.DBCursor._check(DBCursor.java:354)
      at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
      at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
      at sita.co.za.common.UserDAO.findAllusers(UserDAO.java:283)
      at sita.co.za.gui.CreateUserGUI.<init>(CreateUserGUI.java:352)
      at sita.co.za.gui.LoginGUI.actionPerformed(LoginGUI.java:141)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$500(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)

Nov 10, 2015 1:20:50 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
WARNING: null
java.io.IOException: couldn't connect to [/00.0.0.27:27017] bc:java.net.ConnectException: Connection timed out: connect
      at com.mongodb.DBPort._open(DBPort.java:205)
      at com.mongodb.DBPort.go(DBPort.java:94)
      at com.mongodb.DBPort.go(DBPort.java:75)
      at com.mongodb.DBPort.findOne(DBPort.java:129)
      at com.mongodb.DBPort.runCommand(DBPort.java:138)
      at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:422)
      at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:409)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:207)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:224)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:224)
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
      at com.mongodb.DBCursor._check(DBCursor.java:354)
      at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
      at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
      at sita.co.za.common.UserDAO.findAllusers(UserDAO.java:283)
      at sita.co.za.gui.CreateUserGUI.<init>(CreateUserGUI.java:352)
      at sita.co.za.gui.LoginGUI.actionPerformed(LoginGUI.java:141)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$500(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
0
chalie001Author Commented:
ok i fix that i got the correct ip now
am geting this error now
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/mongodb/Function
      at sita.co.za.common.UserDAO.findAllUsers(UserDAO.java:183)
      at sita.co.za.gui.CreateUserGUI.<init>(CreateUserGUI.java:353)
      at sita.co.za.gui.LoginGUI.actionPerformed(LoginGUI.java:141)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$500(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.mongodb.Function
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 39 more
0
gurpsbassiCommented:
NoClassDefFoundError: com/mongodb/Function

I'm not sure where you code is referencing this class
0
chalie001Author Commented:
the error is when am calling this method
public DBObject findByUsername(String username){
            MongoClient mongo = new MongoClient("00.0.0.00", 20000);
              DBCollection dbCollection = mongo.getDB("databasename").getCollection("table name");
             // DBCollection dbCollection =  ConnectToDB.getDB("system").getCollection("users");
              DBObject criteria = new BasicDBObject("columnname", username);
              return dbCollection.findOne(criteria);
            }
0
gurpsbassiCommented:
hold on a minute.
I have no idea what you are doing. You are all over the place!

Going back to the requirements:

I am trying to help you with requirement no 1 that is populating the combo box with initial data.

In order to do this you have to :
(a) read from the database through a DAO
(b) return the data in a format that your front end would understand.

Do we have initial data in the combo box yet????
0
chalie001Author Commented:
no we don't have initial data am geting the error when i go to screen
0
gurpsbassiCommented:
Why is your code calling findbyusername on loading the screen?

It should only call that on a event in the combobox.

On load it needs to call findallusers
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chalie001Author Commented:
ok i change to this

usernamecomboUpt.addItemListener(itemListener);
 Map<String, DBObject> allusers = dao.findAllUsers();

        for(String key : allusers.keySet()){
        	usernamecomboUpt.addItem(key);
        }


public Map<String, DBObject> findAllUsers(){
		 MongoClient mongo = new MongoClient("00.00.00", 27017);
		  DBCollection dbCollection = mongo.getDB("dsn").getCollection("users");
		  DBCursor cursor = dbCollection.find();
		  Map<String, DBObject> allUsers = new HashMap<>();
		  while(cursor.hasNext()){
		   DBObject dbObj = cursor.next();
		   allUsers.put((String)dbObj.get("username"), dbObj);
		 }
		  return allUsers;
		}

Open in new window


but geting error
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/mongodb/Function
      at sita.co.za.common.UserDAO.findAllUsers(UserDAO.java:184)
      at sita.co.za.gui.CreateUserGUI.<init>(CreateUserGUI.java:355)
      at sita.co.za.gui.LoginGUI.actionPerformed(LoginGUI.java:141)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$500(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.mongodb.Function
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 39 more
0
gurpsbassiCommented:
are any of your queries from java working against mongo?
0
gurpsbassiCommented:
Where did you get your driver from?
0
chalie001Author Commented:
this is the drive i have
dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>2.11.3</version>
        </dependency>

i have not test other query,am trying to find out if i can connect to db
0
chalie001Author Commented:
when i use this to connect to db i can log in but the combo box is empty

public class UserDAO {

	private ConnectToDB connection = null;
	private DBCollection collection = null;
	private BasicDBObject document = null;
	private BasicDBObject searchQuery = null;
	private DBCursor cursor = null;
	private ArrayList<DBObject> allUsers, newUsers = null;
	private DBObject record = null;
	private BasicDBObject userSets = null, fieldSets = null; 
	private LogFile log = null;
	private ArrayList<User> duplicates = null;
	 
	
	
	public UserDAO() {
		
		connection = new ConnectToDB();
		collection = connection.getDB().getCollection("user");
		document = new BasicDBObject();
		allUsers = new ArrayList<DBObject>();
		log = new LogFile();
		duplicates = new ArrayList<User>();
		newUsers = new ArrayList<DBObject>();
	}

public Map<String ,DBObject> findAllusersT()
	{
		cursor = collection.find();
		
		Map<String, DBObject> allUserss = new HashMap<>();
		
		allUserss.equals(allUsers);
		
		while(cursor.hasNext())
		{
			allUsers.add(cursor.next());
			//allUserss.add(cursor.next());
		}
		
		return allUserss;		
	}
}

Open in new window

0
chalie001Author Commented:
i have make some progress i can pull user from database to combo box
combo
0
chalie001Author Commented:
now i what to populate that user details name and surname
0
chalie001Author Commented:
i what to populate user like this
import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

import java.sql.*;

 

public class SwingSearchApp extends JFrame implements ActionListener {

 

//Initializing Components

    JLabel lb, lb1, lb2, lb3, lb4, lb5;

    JTextField tf1, tf2, tf3, tf4, tf5;

    JButton btn;

 

    //Creating Constructor for initializing JFrame components

    SwingSearchApp() {

        //Providing Title

        super("Fetching Student Information");
        lb5 = new JLabel("Enter Name:");
        lb5.setBounds(20, 20, 100, 20);
        tf5 = new JTextField(20);
        tf5.setBounds(130, 20, 200, 20);

 

        btn = new JButton("Submit");
        btn.setBounds(50, 50, 100, 20);
        btn.addActionListener(this);

 

        lb = new JLabel("Fetching Student Information From Database");
        lb.setBounds(30, 80, 450, 30);
        lb.setForeground(Color.red);
        lb.setFont(new Font("Serif", Font.BOLD, 20));
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(500, 500);

 

        lb1 = new JLabel("U_Name:");
        lb1.setBounds(20, 120, 100, 20);
        tf1 = new JTextField(50);
        tf1.setBounds(130, 120, 200, 20);
        lb2 = new JLabel("U_Mail:");
        lb2.setBounds(20, 150, 100, 20);
        tf2 = new JTextField(100);
        tf2.setBounds(130, 150, 200, 20);
        lb3 = new JLabel("U_Pass:");
        lb3.setBounds(20, 180, 100, 20);
        tf3 = new JTextField(50);
        tf3.setBounds(130, 180, 200, 20);
        lb4 = new JLabel("U_Country:");
        lb4.setBounds(20, 210, 100, 20);
        tf4 = new JTextField(50);
        tf4.setBounds(130, 210, 100, 20);
        setLayout(null);

 

        //Add components to the JFrame

        add(lb5);
        add(tf5);
        add(btn);

 

        add(lb);
        add(lb1);
        add(tf1);
        add(lb2);
        add(tf2);
        add(lb3);
        add(tf3);
        add(lb4);
        add(tf4);

 

        //Set TextField Editable False

        tf1.setEditable(false);
        tf2.setEditable(false);
        tf3.setEditable(false);
        tf4.setEditable(false);

    }

 

    public void actionPerformed(ActionEvent e) {

        //Create DataBase Coonection and Fetching Records

 

        try {

            String str = tf5.getText();

 

            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521", "sandeep", "welcome");
            PreparedStatement st = con.prepareStatement("select * from emp where uname=?");
            st.setString(1, str);

 

            //Excuting Query

            ResultSet rs = st.executeQuery();

 

            if (rs.next()) {
                String s = rs.getString(1);
                String s1 = rs.getString(2);
                String s2 = rs.getString(3);
                String s3 = rs.getString(4);

 

                //Sets Records in TextFields.

                tf1.setText(s);
                tf2.setText(s1);
                tf3.setText(s2);
                tf4.setText(s3);

            } else {

                JOptionPane.showMessageDialog(null, "Name not Found");

            }

 

            //Create Exception Handler

        } catch (Exception ex) {

 

            System.out.println(ex);

        }

    }

//Running Constructor

 

    public static void main(String args[]) {

        new SwingSearchApp();

    }

} 

Open in new window

0
gurpsbassiCommented:
i have make some progress

Firstly, please explain what you did.
It's hard for me to help you unless you keep me updated of changes.
0
chalie001Author Commented:
oh i change the method to this
public Map<String ,DBObject> findAllusersT()
	{
		cursor = collection.find();
		Map<String, DBObject> allUserss = new HashMap<>();
		
		
		allUserss.equals(allUsers);
		
		while(cursor.hasNext())
		{
			DBObject dbObj = cursor.next();
			allUserss.put((String)dbObj.get("username"), dbObj);
			
		}
		
		return allUserss;		
	}

and this is how i call the method
usernameCombo.addItemListener(itemListener);        
        Map<String, DBObject> alluserD = dao.findAllusersT();
        for(String key : alluserD.keySet()){
        	usernameCombo.addItem(key);
        }

Open in new window

0
chalie001Author Commented:
dao class

public class UserDAO {

	private ConnectToDB connection = null;
	private DBCollection collection = null;
	private BasicDBObject document = null;
	private BasicDBObject searchQuery = null;
	private DBCursor cursor = null;
	private ArrayList<DBObject> allUsers, newUsers = null,uStatusT = null;
	private DBObject record = null;
	private BasicDBObject userSets = null, fieldSets = null; 
	private LogFile log = null;
	private ArrayList<User> duplicates = null;
	 
	
	
	public UserDAO() {
		
		connection = new ConnectToDB();
		collection = connection.getDB().getCollection("user");
		document = new BasicDBObject();
		allUsers = new ArrayList<DBObject>();
		log = new LogFile();
		duplicates = new ArrayList<User>();
		newUsers = new ArrayList<DBObject>();
	}
	usernameCombo.addItemListener(itemListener);        
        Map<String, DBObject> alluserD = dao.findAllusersT();
        for(String key : alluserD.keySet()){
        	usernameCombo.addItem(key);
        }
		}

Open in new window

0
gurpsbassiCommented:
1.
findAllusersT
Why do you use such bad method names???? 'T' has no relevance.

2.
allUserss
Why 'ss' ??

3.
alluserD
Why 'D' ????

4.
allUserss.equals(allUsers);
What is this for???
Please remove redundant code! Keep it clean!

5. I don't understand what you have done different to allow database connectivity.

Please action all 5 points above and then we can continue.
0
chalie001Author Commented:
ok i chnage to this

usernameCombo.addItemListener(itemListener);        
        Map<String, DBObject> alluserD = dao.findAllusersDb();
        for(String key : alluserD.keySet()){
        	usernameCombo.addItem(key);
        }

public Map<String ,DBObject> findAllusersDb()
	{
		cursor = collection.find();
		Map<String, DBObject> allUsersDb = new HashMap<>();
		
		
		allUsersDb.equals(allUsers);// geting userNAME from DB
		
		while(cursor.hasNext())
		{
			DBObject dbObj = cursor.next();
			allUsersDb.put((String)dbObj.get("username"), dbObj);
			
		}
		
		return allUsersDb;		
	}

this is how am connection to db
public class UserDAO {

	private ConnectToDB connection = null;
	private DBCollection collection = null;
	private BasicDBObject document = null;
	private BasicDBObject searchQuery = null;
	private DBCursor cursor = null;
	private ArrayList<DBObject> allUsers, newUsers = null,uStatusT = null;
	private DBObject record = null;
	private BasicDBObject userSets = null, fieldSets = null; 
	private LogFile log = null;
	private ArrayList<User> duplicates = null;
	 
	
	
	public UserDAO() {
		
		connection = new ConnectToDB();
		collection = connection.getDB().getCollection("user");
		document = new BasicDBObject();
		allUsers = new ArrayList<DBObject>();
		log = new LogFile();
		duplicates = new ArrayList<User>();
		newUsers = new ArrayList<DBObject>();
	}

Open in new window

0
gurpsbassiCommented:
Please action all 5 points above and then we can continue.


You haven't done all 5
0
chalie001Author Commented:
public class UserDAO {

	private ConnectToDB connection = null;
	private DBCollection collection = null;
	private BasicDBObject document = null;
	private BasicDBObject searchQuery = null;
	private DBCursor cursor = null;
	private ArrayList<DBObject> allUsers, newUsers = null,uStatusT = null;
	private DBObject record = null;
	private BasicDBObject userSets = null, fieldSets = null; 
	private LogFile log = null;
	private ArrayList<User> duplicates = null;
	 
	
	
	public UserDAO() {
		
		connection = new ConnectToDB();
		collection = connection.getDB().getCollection("user");// 5 database connection
		document = new BasicDBObject();
		allUsers = new ArrayList<DBObject>();
		log = new LogFile();
		duplicates = new ArrayList<User>();
		newUsers = new ArrayList<DBObject>();
	}
	
	
		public Map<String ,DBObject> findAllusersDb()// 1 method geting username in db
	{
		cursor = collection.find();
		Map<String, DBObject> allUsersDb = new HashMap<>();2 i change it
		
		
		allUsersDb.equals(allUsers);//4 geting username from db
		
		while(cursor.hasNext())
		{
			DBObject dbObj = cursor.next();
			allUsersDb.put((String)dbObj.get("username"), dbObj);
			
		}
		
		return allUsersDb;		
	}
	
	}
	
	

	
	 usernameCombo.addItemListener(itemListener);        
        Map<String, DBObject> alluserUpt = dao.findAllusersDb();
        for(String key : alluserUpt.keySet()){
        	usernameCombo.addItem(key);
        }

Open in new window

0
gurpsbassiCommented:
I need to the the method ConnectToDB()
0
chalie001Author Commented:
its a class i use property file to connect to db instead of hard coding
import com.mongodb.DB;
import com.mongodb.Mongo;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;


/**
 * 
 * 
 *
 */
public class ConnectToDB {
	
	private DB db = null;
	private Mongo mongoClient = null;
	private Properties properties = new Properties();
        private InputStream input = null;
        
	public ConnectToDB() {
	
		getDB();
		
	}
	
	
	private boolean connectToDB() throws Exception{
		input = new FileInputStream("dsnApp.properties");
                properties.load(input);
                
		  this.mongoClient = new Mongo(properties.getProperty("mongoDBipAddress"), Integer.valueOf(properties.getProperty("mongoDBport")));
                  
		  this.db = mongoClient.getDB("dsn");
		  		  
		  if(db != null)
		  {
			  return true;
		  }
		     
		 return false;
	}
	
	
	public DB getDB() {
		
		try {
			if(connectToDB())
			{
				return db;
			}
			else
			{
				connectToDB();
				return db;
			}
		} catch (Exception e) {
			
			System.out.println("Something went wrong while trying to connect to the database..");
			e.printStackTrace();
			return null;
		}
	}
  
}

Open in new window

0
gurpsbassiCommented:
I am stil not clear what you did to resolve

Caused by: java.lang.ClassNotFoundException: com.mongodb.Function
0
chalie001Author Commented:
i remove this method
public DBObject findByUsername(String username){
		MongoClient mongo = new MongoClient("00.0.0.00", 20000);
		  DBCollection dbCollection = mongo.getDB("databasename").getCollection("table name");
		 // DBCollection dbCollection =  ConnectToDB.getDB("system").getCollection("users");
		  DBObject criteria = new BasicDBObject("columnname", username);
		  return dbCollection.findOne(criteria); 
		}


and replace with
public Map<String ,DBObject> findAllusersDb()
	{
		cursor = collection.find();
		Map<String, DBObject> allUsersDb = new HashMap<>();
		
		
		allUsersDb.equals(allUsers);
		
		while(cursor.hasNext())
		{
			DBObject dbObj = cursor.next();
			allUsersDb.put((String)dbObj.get("username"), dbObj);
			
		}
		
		return allUsersDb;		
	}

Open in new window

0
gurpsbassiCommented:
ok I understand
0
gurpsbassiCommented:
so what is your next question?
0
chalie001Author Commented:
how to populate value based on the username selected on combobox

name
surname

for the user in combobox
0
gurpsbassiCommented:
similar to one of the million questions you have posted.
Add a listener to the combobox. You can add many listeners I believe.

And then get a handle on the text fields to set their value with the current selection in the combobox.

Please read the jcombo box API and search for examples on line.
0
chalie001Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for chalie001's comment #a41226605

for the following reason:

correct
0
gurpsbassiCommented:
chalie001 has accepted his own answer (a41226605) as the solution.
a41226605 states nothing about a solution.
0
chalie001Author Commented:
I did this read from the database through a DAO
0
gurpsbassiCommented:
chalie001 you are making no sense.

You have to select the answer that you used to solve the problem.
The one you selected is not an answer. It is asking a question!
0
chalie001Author Commented:
I did this
Map<String, DBObject> allusers = dao.findAllUsers();

for(String key : allUsers.keySet()){
  jComboBox.addItem(key);
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.