I am facing problems in getting the data displayed in a texfield from database when I am selecting a value in combobox. I am only able to display the first item in the combobox into the textfield as it is by default loading as the page loads. Rest when I am selecting from combobox nothing happens. Please help. This is the place in code I need to work on.
cmbProjects = new JComboBox<String>();
cmbProjects.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String query= "SELECT * FROM PROJECT WHERE PROJ_NAME = ?";
PreparedStatement pst= connection.prepareStatement(query);
pst.setString(1, (String)cmbProjects.getSelectedItem());
ResultSet rs= pst.executeQuery();
while(rs.next()){
textField.setText(rs.getString("PROJ_ID"));
textField_1.setText(rs.getString("PROJ_WO_NUMBER"));
textField_2.setText(rs.getString("PROJ_START_DATE"));
textField_3.setText(rs.getString("PROJ_END_DATE"));
//JTextArea.setText(rs.getString("PROJ_COMMENTS"));
textField_4.setText(rs.getString("PROJ_STATUS"));
textField_5.setText(rs.getString("PROJ_ADDED_BY"));
textField_6.setText(rs.getString("PROJ_ADDED_ON"));
}
}
catch(Exception ex){
}
}
});
cmbProjects.setToolTipText("well");
cmbProjects.setBounds(139, 94, 394, 27);
panelDetails3_1.add(cmbProjects);