我一直在修改MySql表的修改按钮,我在Forme1中有我的表,当我点击Modify bytton时我得到了包含字段的Fomre2,但是当我点击确认我得到了#34; Exception在线程"错误甚至我的代码是非常正确的,它的工作原理是从formT1中的jTable1获取Selected的ID值,将它放在我的SQL语句中,但是在不工作时它向我显示meassage:
"Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1 "
这是我的按钮代码:
private void btnmActionPerformed(java.awt.event.ActionEvent evt) {
school_managment c = new school_managment();
java.sql.Date date = new java.sql.Date(jda.getDate().getTime());
java.sql.Date date1 = new java.sql.Date(jdd.getDate().getTime());
String a = txta.getText().toString();
String d = txt.getText().toString();
int id_index = c.jTable1.getSelectedRow();
DefaultTableModel model = (DefaultTableModel) c.jTable1.getModel();
String selected = model.getValueAt(id_index, 0).toString();
if (id_index != -1) {
try {
con = connection.connect();
String sql = "UPDATE courrier SET DATE_darriver='" + date + "', OBJECTIF_arriver='" + a + "', DATE_depart='" + date1 + "',OBJECTIF_depart='" + d + "' WHERE ID='" + selected + "' ";
st = con.prepareStatement(sql);
st.executeUpdate(sql);
this.setVisible(false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
connection.deconnect(con);
} else {
JOptionPane.showMessageDialog(null, "SELECTEZ LA LIGNE QUE VOUS VELEZ MODIFIER");
}
}