我想从表本身和数据库中删除 JTable
中的 selcetd 行。
这是我的代码:
Object number = jTable1.getValueAt(selectedRow-1, 0);
String sql = "delete from orders where number ="+number;
Statement st = conn.createStatement();
rs = null;
rs = st.executeQuery(sql);
当 excuteQuery()
运行时,出现以下异常:
(java.sql.SQLException) java.sql.SQLException: Can not issue data manipulation statements with executeQuery()
我做错了什么?
最佳答案
这不是异常异常
。
您需要调用 executeUpdate
而不是 executeQuery
。您不能通过调用 executeQuery
方法来更新数据库。要更新数据库中的内容(插入、更新、删除),您需要调用 executeUpdate
方法,它不会返回 ResultSet
而是返回给您一个 int
值。
int result = st.executeUpdate(sql);
关于java - SQLException 从 JTable 和数据库中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27443938/