我想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()
我究竟做错了什么?
这不是一个Abnormal Exception
。
您需要致电executeUpdate
而不是executeQuery
。您不能通过调用executeQuery
方法来更新数据库。要更新数据库中的某些内容(插入,更新,删除),您需要调用executeUpdate
method,它不会返回ResultSet
,而是返回一个int
值。
int result = st.executeUpdate(sql);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句