[英]how to update Jtable based on the items i click in my JComboBox?
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. 我想用下面的jcombobox中的选定项目填充我的jtable,这是我为执行该操作而编写的代码,但并非如此。
please am still new in java so i will appreciation the help. 请在Java中还是一个新手,所以我将感谢您的帮助。
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"
. 我认为您想将所选项目的字符串值与给定的字符串进行比较: "LAND & BUILDINGS"
。
In any case ==
is not the proper way to compare strings in java. 在任何情况下, ==
都不是在Java中比较字符串的正确方法。 Take a look to this topic: How do I compare strings in Java . 看一下以下主题: 如何在Java中比较字符串 。
As stated there: 如此处所述:
==
tests for reference equality. ==
测试引用相等性。 .equals()
tests for value equality. .equals()
测试值是否相等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.