如何将值从comboBox传递给sql语句?
String name = comboBox.getSelectedItem().toString();
String sql = "SELECT surname FROM employee WHERE etairia = name ";
result = statement.executeQuery(sql);
答案 0 :(得分:2)
试试这个:
String name = comboBox.getSelectedItem().toString();
String sql = "SELECT surname FROM employee WHERE etairia = (?)";
statement = conn.prepareStatement(sql); // conn is Connection
statement.setString(1, name); // '1' is the param index, it's always start from 1, not from zero
result = statement.executeQuery();