我正在基于摇摆的项目工作,并使用预备语句,但它给出异常,如超出范围,当我使用参数,不要把'?' 但简单?然后显示异常,如"jdbc语法错误检查附近的手册??,?" 在第一行"我很困惑发生了什么.检查我的代码有什么问题?
private void AddActionPerformed(java.awt.event.ActionEvent evt) {
if (((JTextField) chose.getDateEditor().getUiComponent()).getText() == null) {
String sql = "INSERT INTO expance1 ( Breakfast,Date) VALUES (?,?)";
} else {
String sql = "INSERT INTO expance1 ( Breakfast,Date) VALUES (?,?)";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, breakfast.getText());
pst.setString(2, ((JTextField) chose.getDateEditor().getUiComponent()).getText());
pst.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "insert sucessfully");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
} finally {
try {
rs.close();
pst.close();
} catch (Exception e) {
}
}
}
}
Run Code Online (Sandbox Code Playgroud)