How to Delete selected table data from DB???? HELP
I'm trying to delete a selected row from a jTable that was queried from a database. I'm getting stuck on how to create an actionlistener that deletes the selected (highlighted) data from the database, here is what I have. I know after the connection it is probably totally wrong but I think you can get the idea from it....
Code :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
try{
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection ("jdbc:mysql://Lane-PC:3306/JavaApp","user","user");
PreparedStatement ps = con.prepareStatement("DELETE FROM supportTickets (?,?,?,?,?,?)");
ps.executeUpdate(jTable1.getSelectedRows());
}
catch (SQLException se){
JOptionPane.showMessageDialog(null,"SQL Exception, Database Connection Error","error",JOptionPane.PLAIN_MESSAGE);
while (se !=null){
System.out.println("State :"+ se.getSQLState());
System.out.println("Message :"+ se.getMessage());
System.out.println("State :"+ se.getErrorCode());
se = se.getNextException();
}
} catch (Exception e){
System.out.println(e);
}
}