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);
}
我越来越不明白为什么会这样。
最佳答案
CASE
是一个MySQL reserved word。要么转义该单词,要么更改数据库列名,后者最好避免完全转义。
String sql =
Insert into eyeglass
(Brand, Model, Size, Color, Type, `Case`, Lens, Style, Warranty, Remarks) values(?,?,?,?,?,?,?,?,?,? )";
关于java - 我的SQL语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26191259/