我已经使用了下面相同的方法用于其他swing组件的actionlisteners并且工作正常,只要我将它用于JoptionPane它就会出错! (字符串一,二,三和四是我的JOptionPane中的文本字段,对象message2包含它们)
insertButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object initialSelectionValue = null;
Statement statement = null;
if (SisSelected == true) {
String insert = "INSERT INTO `S` VALUES ('" + one + "','"
+ two + "','" + three + "','" + four + "');";
JOptionPane
.showInputDialog(message2, initialSelectionValue);
one.getText();
two.getText();
three.getText();
four.getText();
try {
statement = ResultSetTableModelFactory.connection
.createStatement();
statement.executeUpdate(insert);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
displayQueryResults("select * from S;");
}