Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: JComboBox fill with text after selected another JComboBox conected with database SQLlite

  1. #1
    Junior Member
    Join Date
    Nov 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JComboBox fill with text after selected another JComboBox conected with database SQLlite

    Can someone please advise me. is it possible to change JComboBox (in my case comboBoxGenderIDCard ) item based on selected item from another JComboBox (in ma case comboBoxIDNumberIDCard), which is connected to the SQLite database (my case employee).

    This is the code:
    comboBoxIDNumberIDCard = new JComboBox();
    comboBoxIDNumberIDCard.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    String sql ="select * from employee where EmployeeID=?";
    PreparedStatement pst = conn.prepareStatement(sql);
    pst.setString(1, (String)comboBoxIDNumberIDCard.getSelectedItem());

    ResultSet rs=pst.executeQuery();

    while(rs.next()){
    txtnameIDCard.setText(rs.getString("Firstname")); // for JText working perfectly
    txtIDSurname.setText(rs.getString("Surname"));

    comboBoxGenderIDCard.addItem(rs.getString("Gender" )); // I tried this code, but is not working!
    }
    }catch (Exception e1) {
    e1.printStackTrace();
    }
    }
    });

    My first JComboBox (comboBoxGenderIDCard) item is defined already (two option Male or Female).


    JComboBox<String> comboBoxGenderIDCard = new JComboBox<String>();
    comboBoxGenderIDCard.setEditable(true);
    comboBoxGenderIDCard.addItem("Select");
    comboBoxGenderIDCard.addItem("Male");
    comboBoxGenderIDCard.addItem("Female");
    comboBoxGenderIDCard.setBounds(138, 167, 182, 19);
    IDEmployeeCard.add(comboBoxGenderIDCard);
    Last edited by Sony; November 29th, 2022 at 09:39 AM.

Similar Threads

  1. Calculate end date based on date selected
    By hdiazr in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 20th, 2022, 07:29 PM
  2. Replies: 0
    Last Post: November 24th, 2017, 02:44 PM
  3. get value from jTable to jDateChooser
    By bhapux in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 12th, 2014, 10:18 PM
  4. How to fulfill this program
    By azizmaiden in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 17th, 2013, 03:44 PM
  5. How to insert date in database
    By AJAXx195 in forum JDBC & Databases
    Replies: 1
    Last Post: January 24th, 2012, 03:26 PM

Tags for this Thread