gpt4 book ai didi

java - Java中使用SQL删除记录

转载 作者:行者123 更新时间:2023-11-29 13:40:06 25 4
gpt4 key购买 nike

更新:我尝试了以下建议,但仍然不起作用。当尝试employeeid=1时,它确实说成功,但是进入mysql命令行,它仍然显示那里的记录。

我尝试查看不同的帖子,我的插入工作正常,但由于某种原因我无法使用删除功能。

我正在尝试删除一条记录,但不断收到错误消息。运行 mysql 和 netbeans。请帮忙,谢谢。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:

try {

statement.executeUpdate("INSERT INTO `abcinc`.`employees`"
+ "(`EmployeeID`,`First_Name`,`Last_Name`,`Birthday`,`Dept_Name`)VALUES("
+ "'" + jTextField1.getText() + "',"
+ "'" + jTextField2.getText() + "',"
+ "'" + jTextField3.getText() + "',"
+ "'" + jTextField4.getText() + "',"
+ "'" + jTextField5.getText() + "');");

JOptionPane.showMessageDialog(null, "Successful Update!!!", "Database Messages",
JOptionPane.OK_OPTION);
}
catch(SQLException error){
JOptionPane.showMessageDialog( null, error.getMessage(), "Database Messages",
JOptionPane.ERROR_MESSAGE );
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {

statement.executeUpdate("DELETE FROM `abcinc`.`employees`"
+ "WHERE (`EmployeeID`,`First_Name`,`Last_Name`,`Birthday`,`Dept_Name`)VALUES("
+ "'" + jTextField1.getText() + "',"
+ "'" + jTextField2.getText() + "',"
+ "'" + jTextField3.getText() + "',"
+ "'" + jTextField4.getText() + "',"
+ "'" + jTextField5.getText() + "');");

JOptionPane.showMessageDialog(null, "Successful Update!!!", "Database Messages",
JOptionPane.OK_OPTION);
}
catch(SQLException error){
JOptionPane.showMessageDialog( null, error.getMessage(), "Database Messages",
JOptionPane.ERROR_MESSAGE );
}
}

最佳答案

删除不遵循该语法。

尝试类似的事情

DELETE FROM mytable WHERE mycolumn='X' AND myothercolumn='Y';

see docs here

关于java - Java中使用SQL删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18187748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com