【问题标题】:SQLException deleting row from JTable and databaseSQLException 从 JTable 和数据库中删除行
【发布时间】:2015-02-11 04:21:32
【问题描述】:

我想从表本身和数据库中删除 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 方法。

标签: java mysql swing jdbc jtable


【解决方案1】:

这不是Abnormal Exception

您需要拨打executeUpdate 而不是executeQuery。您不能通过调用executeQuery 方法来更新数据库。要更新数据库中的某些内容(插入、更新、删除),您需要调用 executeUpdate 方法,它不会返回 ResultSet,而是返回 int 值。

int result = st.executeUpdate(sql);

More Info

【讨论】:

    猜你喜欢
    • 2018-06-26
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2012-05-04
    • 2020-01-16
    相关资源
    最近更新 更多