Exemplo n.º 1
0
  public void excluirPM() {
    if (tbPart.getSelectedRow() != -1) {
      int resposta =
          JOptionPane.showConfirmDialog(
              this,
              "Confirma exclusão do Policial Militar?",
              "Confirmação",
              JOptionPane.YES_NO_OPTION);
      if (resposta == JOptionPane.YES_OPTION) {

        // System.out.println("Exclui!!!");

        int codigo = pegaCodigo();

        try {
          con.conecta();

          // String query = ();

          PreparedStatement cnd;
          cnd = con.conecta().prepareStatement("delete from usuario where cod_policial=?");
          cnd.setInt(1, codigo);
          cnd.executeUpdate();
          con.desconecta();
          JOptionPane.showMessageDialog(null, "registro excluído com sucesso!");
          atualizaTabela();
        } catch (SQLException ex) {
          Logger.getLogger(ManterPM.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    } else {
      JOptionPane.showMessageDialog(
          this, "Selecione um nome da lista!", "Erro", JOptionPane.ERROR_MESSAGE);
    }
  }