gpt4 book ai didi

java - 删除数据库中的选定行

转载 作者:行者123 更新时间:2023-11-30 07:13:14 25 4
gpt4 key购买 nike

为什么这对我不起作用?我不断收到错误消息:

java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

我的代码:

private void speler_deleteActionPerformed(java.awt.event.ActionEvent evt) {
int row = tbl_spelers.getSelectedRow();
int SpelerID = (int) tbl_spelers.getValueAt(row, 0);
Speler speler = new Speler();

try {
DBClass databaseClass = new DBClass();
Connection connectie = databaseClass.getConnection();
// NOG ONVEILIG - WACHTEN OP DB SELECT IN DBCLASS!!!
String deleteQry = "DELETE FROM `Speler` WHERE SpelerID = " + SpelerID + ";";
ResultSet rs = databaseClass.GetFromDB(deleteQry);
} catch (SQLException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
}
}

最佳答案

你必须使用 excuteUpdate()用于删除

excuteUpdate() 的文档

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.

哪里executeQuery()

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

关于java - 删除数据库中的选定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19638090/

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