How to send a message when trying to delete a record that has a foreign key relationship?

0

What I need is that when the user presses the button to delete the record, it does not allow me to delete if it is related to another table, that is, I have a table grupo_cod, related to another one called items, at the moment to delete a record grupo_cod I must verify if it has a relation in items .. if so, send a message to the user, otherwise delete it ..

if(operacion=="eliminar"){
        int a =JOptionPane.showConfirmDialog(null, "Esta seguro que dese eliminar", "Eliminar", JOptionPane.YES_NO_OPTION);
         if(a==JOptionPane.YES_OPTION){
        con.conectar();

        con.ejecutarSentencia("delete from grupos where gru_cod="+txt_id.getText());
        con.CerrarConexion();
       JOptionPane.showMessageDialog(null, "Eliminado con exito");
       btn_cancelarActionPerformed(null);                     

    } 

This is the code I use to delete, what I need is for you to type a comparison so that you know that if the record is being used in another table do not delete and send an SMS

    
asked by Vale 23.10.2017 в 18:58
source

0 answers