What I have done is used a listener to perform a action anytime the previous comboBox is changed. The problem I am having is, I need to have 2 different tables from my database to fill my comboBox based on a radioButton which is selected. I can complete the action without issue for the first "if" statement however, the second will not work and repeatedly sends the error "ResultSet Closed".
Here is the code so this all makes more sense:
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent arg0) {
comboBox_1.removeAllItems();
Object hz = comboBox.getSelectedItem();
hzt = hz.toString();
try{
c = DriverManager.getConnection("jdbc:sqlite:MAAWB.db");
stmt = c.createStatement();
String id = "SELECT Threat_Hazard_ID FROM Threats_Hazards_Categories WHERE Hazard = '" + hzt + "'";
THid = stmt.executeQuery(id);
THids = THid.getString("Threat_Hazard_ID");
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(radioButton.isSelected() != false){
try {
String hazardCP = "SELECT HazardCP FROM Hazard_CP WHERE Threat_Hazard_Id = '" + THids + "'";
hcp = stmt.executeQuery(hazardCP);
while(hcp.next()){
Hcp = hcp.getString("HazardCP");
String newHcp = (Hcp);
comboBox_1.addItem(newHcp);
}
}
catch (SQLException e) {
e.printStackTrace();
}finally{
try{
stmt.close();
hcp.close();
THid.close();
c.close();
}catch (Exception e){
JOptionPane.showMessageDialog(null, "ERROR CLOSE");
}
}
}
else if(radioButton_1.isSelected() != false){
try {
String threatCP = "SELECT ThreatCP FROM Threat_CP WHERE Threat_Hazard_Id = '" + Tid + "'";
tcp = stmt.executeQuery(threatCP);
while(tcp.next()){
Tcp = tcp.getString("ThreatCP");
String newTcp =(Tcp);
comboBox_1.addItem(newTcp);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try{
stmt.close();
tcp.close();
THid.close();
c.close();
}catch (Exception e){
JOptionPane.showMessageDialog(null, "ERROR CLOSE in threat");
}
}
}
}
}
``});
Aucun commentaire:
Enregistrer un commentaire