i want to populate my jtable with selected items in my jcombobox below is the code i wrote to perform the action but it does not.
please am still new in java so i will appreciation the help.
if(AssetCategories.getSelectedItem() == "LAND & BUILDINGS"){
try {
String sql = "SELECT Description FROM items where Description_Code = 'LB' Order by id";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
dep_report.setModel(DbUtils.resultSetToTableModel(rs));
} catch (SQLException ex) {
Logger.getLogger(DepreciationReport.class.getName()).log(Level.SEVERE, null, ex);
}
}
This condition doesn't make sense:
if(AssetCategories.getSelectedItem() == "LAND & BUILDINGS")
You're trying to compare an Object with a String (apples and oranges). I think you want to compare a String value of selected item with a given String: "LAND & BUILDINGS"
.
In any case ==
is not the proper way to compare strings in java. Take a look to this topic: How do I compare strings in Java.
As stated there:
==
tests for reference equality..equals()
tests for value equality.