我尝试在 JTable 中选中已由 Sql 查询填充的复选框后,在 JLabel 中显示项目数量的较低值,并通过单击 JButton,这些值将显示在 JLabel 中。
我尝试列出所选项目以在 jlabel 中显示较低的项目数量。
private void ButtonbtActionPerformed(java.awt.event.ActionEvent evt) {
String bnr = BomReferenceNoCB.getSelectedItem().toString();
ArrayList<String> al = new ArrayList<>();
for (int i = 0; i < BOMT.getRowCount(); i++) {
if (BOMT.getValueAt(i, 0).equals(true)) {
String ta = (String) BOMT.getValueAt(i, 3);
al.add((String) ta);
}
}
String at = "'" + String.join(",", al) + "'";
try {
PreparedStatement ps = DataBase.mycon().prepareStatement("select (sum(`Item Qty`/Qty)"
+ " as available from '" + bnr + "' where `Part No` is not null and `Part No`" "not in (?) group by `Part No` order by (sum(`Item Qty`)/Qty) limit 1");
ps.setString(1, at);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String product = rs.getString("available");
BOMProductsL.setText(product);
System.out.println(product);
}
ps.close();
DataBase.mycon().close();
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Product loading error");
}
}