【发布时间】:2017-09-28 09:25:42
【问题描述】:
在这段代码中,它只是从JTable 中删除行,我想从数据库中删除
当运行它时,它会从JTable 中删除并出现错误:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2 但没有从数据库中删除如何解决这个问题?
private final JPanel panel_09 = new JPanel();
JScrollPane scrollPane_09 = new JScrollPane();
final DefaultTableModel TableModel09 = new DefaultTableModel(new String[]{"Picture", "Item", "Price", "After Discount"}, 0);
final JTable table_09 = new JTable(TableModel09);
JButton btnNewButton_09 = new JButton("Delete Item");
btnNewButton_09.addActionListener ( new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
int selectedPlanet = table_09.getSelectedRow();
TableModel09.removeRow((int) selectedPlanet);
Object desc = table_09.getModel().getValueAt(selectedPlanet, 4);
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/login", "root", "123");
String query = "delete from flyer_item where discount=desc";
java.sql.PreparedStatement ps = conn.prepareStatement(query);
ps.setString(1, (String) desc);
ps.executeUpdate();
} catch (Exception ex) {
System.err.println(ex);
}
}
}
);
【问题讨论】:
-
您是否尝试调试您的问题?
-
如果@YCF_L 的回答回答了您的问题,那么请接受答案。请查看What should I do when someone answers my question? 了解更多信息。
标签: java mysql arrays swing jdbc