这是公共全局变量:
public static String s;
这是SQL查询 - >规范它的工作,但没有条件WHERE
String query = "SELECT * FROM `asistente` WHERE `sectie`="+s;
System.out.println(s);
Statement st;
ResultSet rs;
S->等于NULL
填充ComboBox - >它的工作
public void fillComboBox() {
try {
String a = "jdbc:mysql://localhost/licenta";
Connection connection = DriverManager.getConnection(a, "root", "");
String query = "SELECT * FROM `sectii`";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
comboBoxSectie.addItem(rs.getString("sectie"));
comboBoxFilterSectie.addItem(rs.getString("sectie"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
这里我试图给出来自组合框的值
public ModificareDB() {
comboBoxFilterSectie = new JComboBox();
comboBoxFilterSectie.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
s=(String) comboBoxFilterSectie.getSelectedItem();
System.out.println(s);
}
});
- > s等于选定的值
如何在查询中使用从comboBox中选择的值?