我正在尝试在 netbeans 上运行以下代码,但它抛出此错误“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以获取在 '?, esalary=?, eage 附近使用的正确语法=?, egender=?, edept=? 其中 eid = ?' 在第 1 行"。请帮我解决错误
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
//open connection
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useSSL=false","root","BakerStreet@221b");
//mysql query to update
String sql = "update emp set ename=?, esalary=?, eage=?, egender=?, edept=? where eid = ?";
PreparedStatement ptsmt = con.prepareStatement(sql);
ptsmt.executeUpdate(sql);
ptsmt.setString(1,empName.getText());
ptsmt.setInt(2,Integer.parseInt(empSal.getText()));
ptsmt.setInt(3,Integer.parseInt(empAge.getText()));
ptsmt.setString(4,empGen.getText());
ptsmt.setString(5,empDep.getText());
ptsmt.setInt(6,Integer.parseInt(id.getText()));
ptsmt.executeUpdate();
JOptionPane.showMessageDialog(this, "Record updated Successfully");
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}