I am trying to make the if statement work but I dont know how's the right way to express it.
Button button_2 = new Button("Delete");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Here I get the selection of the row and column which I intend to manipulate later.
int column =0;
int row = table_1.getSelectedRow();
String id= table_1.getModel().getValueAt(row, column).toString();
if (id==null) { // won't work as it should ?
JOptionPane.showMessageDialog(null, "Please select a row to delete!");
}else {
try{
String query3 = "DELETE FROM hostel_dtrm WHERE id=?";
PreparedStatement pst= conn1.prepareStatement(query3);
pst.setString(1, id);
pst.executeUpdate();
// Printing the results after Row Deletion
String query2= "SELECT * FROM hostel_dtrm";
PreparedStatement psts= conn1.prepareStatement(query2);
ResultSet rs=psts.executeQuery();
table_1.setModel(DbUtils.resultSetToTableModel(rs));
// Closing stuff
pst.close();
rs.close();
JOptionPane.showMessageDialog(null, "Row Deleted");
}catch(Exception err){
System.err.println(err);
}
}
}
});
Aucun commentaire:
Enregistrer un commentaire