I have a query to fetch the name and id of companies. I am able to fetch all the companies but my issue is with the id of the companies. I have a combo box to display list of companies and another label which displays the id of the company selected in the combo box.
Here is my issue, when i change the selected company in the combo box, the label showing the id still remains displays the id of the initial company selected. Is there a way that i could continuously query the database to update the id?
PS I display companies in the combo box with reference no.
public AssignCompanies() { initComponents(); conn = DBConnection.ConnectDB(); FindCompanyID(); } public void FindCompanyID() { String sql = "Select * from Company where ID = "+FindSelectedCompany.getSelectedItem(); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while(rs.next()) { String getSelectedCompany = rs.getString("Reference Number"); seats.setText(getSelectedCompany); } } }