gpt4 book ai didi

java - 从多个表中删除记录时出现 "java.sql.SQLSyntaxErrorException: ORA-00928: missing SELECT keyword"

转载 作者:行者123 更新时间:2023-12-01 16:51:43 24 4
gpt4 key购买 nike

我尝试使用 java 删除针对 attendnt_N 的行,但收到​​此异常 java.sql.SQLSyntaxErrorException: ORA-00928: 缺少 SELECT 关键字。如果有人知道其删除/解决方案,请告诉我。这是我的代码:

ResultSet rss = stmt.executeQuery("select * from ATTENDANCE, ATTENDANTS");
System.out.println(attendnt_N); //working fine
int countd = 0;
while(rss.next()){
countd++;
if(attendnt_N.equalsIgnoreCase(rss.getString(1))){
String dell = ("(DELETE FROM ATTENDANCE, ATTENDANTS WHERE Attendant_Name ='" + attendnt_N + "')");
//String del = ("(DELETE FROM ATTENDANCE WHERE Attendant_Name ='" + attendnt_N + "')");
//String dell = ("(DELETE FROM ATTENDANTS WHERE Attendant_Name ='" + attendnt_N + "')");
//stmt.executeQuery(del);
stmt.executeQuery(dell);
JOptionPane.showMessageDialog(null, "Record against "+ attendnt_N +" is Deleted");
System.out.println("Deleted");
}
}
if(countd == 0){
JOptionPane.showMessageDialog(null, "Record against "+ attendnt_N +" does not exist");
System.out.println("Not Deleted");
faceFrame.repaint();
delBut.setEnabled(true);
}

最佳答案

首先,您应该在发帖时隐藏注释的 sql 查询,这会使代码更难阅读。

蒂姆·比格莱森是对的。您应该只按表执行一次删除,但您还需要更改语句中使用的方法。stmt.executeQuery(dell) 用于选择查询。
对于更新,请使用 stmt.executeUpdate(dell)查看文档:

结果集executeQuery(String sql)

Executes the given SQL statement, which returns a single ResultSet object.

intexecuteUpdate(String sql)

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

关于java - 从多个表中删除记录时出现 "java.sql.SQLSyntaxErrorException: ORA-00928: missing SELECT keyword",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38939599/

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