【发布时间】:2014-10-04 08:57:36
【问题描述】:
try {
String sql = "Insert into eyeglass (Brand, Model, Size, Color, Type, Case, Lens, Style, Warranty, Remarks) values(?,?,?,?,?,?,?,?,?,? )";
pst = conn.prepareStatement(sql);
pst.setString(1, txtBrand.getText());
pst.setString(2, txtModel.getText());
pst.setString(3, txtSize.getText());
pst.setString(4, txtColor.getText());
pst.setString(5, txtType.getText());
pst.setString(6, txtCase.getText());
pst.setString(7, txtLens.getText());
pst.setString(8, txtStyle.getText());
pst.setString(9, txtWarranty.getText());
pst.setString(10, txtRemarks.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "Saved");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
我收到了ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Case, Lens, Style, Warranty, Remarks) values(",",",",",",",",",")' in line 1,但我不明白为什么会这样。
【问题讨论】:
-
你在mysql中试过同样的sql吗?例如:打印 sql,复制并在 mysql 中运行。我认为你有引号问题。单
'或双"。 -
不相关...joptionpane 将如何使用“java.lang.Exception...”之类的东西 e.getMessage() 或 e.printStackTrace();