Example #1
0
 public int exibirDia(ResultSet rs) throws SQLException {
   // position to first record
   boolean moreRecords = rs.next();
   // If there are no records, display a message
   if (!moreRecords) {
     return 0;
   }
   modelolistaDia.addElement(rs.getString(1));
   while (rs.next()) {
     modelolistaDia.addElement(rs.getString(1));
   }
   return 1;
 }
Example #2
0
 private void jButton1ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
   // TODO add your handling code here:
   modelolistaDisc.clear();
   ResultSet rs = null;
   ConectarAOBanco cd = new ConectarAOBanco();
   String nome = jTextField3.getText();
   nome = nome.toUpperCase();
   String query =
       "SELECT nome FROM universidade.disciplina WHERE UPPER(nome) like'%"
           + nome
           + "%' ORDER BY nome";
   cd.ConectarBanco();
   rs = cd.query(query);
   int resultado;
   try {
     resultado = exibirDisc(rs);
     if (resultado == 1) {
       jList1.setModel(modelolistaDisc);
     } else {
       JOptionPane.showMessageDialog(this, "Disciplina não foi encontrada");
     }
   } catch (SQLException sqlex) {
     sqlex.printStackTrace();
   }
 } // GEN-LAST:event_jButton1ActionPerformed
Example #3
0
  private void jButton3ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    if (jList1.isSelectionEmpty())
      JOptionPane.showMessageDialog(this, "Selecione alguem pra ser removido!");
    else {
      String nome = jList1.getSelectedValue().toString();
      ConectarAOBanco cd = new ConectarAOBanco();
      cd.ConectarBanco();
      ResultSet rs = null;
      try {
        String queryidprof = "SELECT id FROM universidade.professor WHERE nome = '" + nome + "'";
        rs = cd.query(queryidprof);
        String idprof = getInfo(rs);
        String queryidaluno =
            "SELECT id FROM universidade.estudante WHERE tutor = '" + idprof + "'";
        rs = cd.query(queryidaluno);
        String idaluno = getInfo(rs);
        int r = 0;
        String querydeleteensina =
            "DELETE FROM universidade.ensina WHERE id_prof = '" + idprof + "'";
        cd.updatequery(querydeleteensina);
        String querydeletafrequenta =
            "DELETE FROM universidade.frequenta WHERE id_est ='" + idaluno + "'";
        cd.updatequery(querydeletafrequenta);
        String querydeletaaluno =
            "DELETE FROM universidade.estudante WHERE tutor = '" + idprof + "'";
        cd.updatequery(querydeletaaluno);
        String querydeletaprofessor =
            "DELETE FROM universidade.professor WHERE id='" + idprof + "'";
        r = cd.updatequery(querydeletaprofessor);
        if (r == 1) {
          modelolistaNome.removeElement(nome);
          JOptionPane.showMessageDialog(this, "Professor removido");
        } else JOptionPane.showMessageDialog(this, "Professor não removido");

      } catch (SQLException ex) {
        ex.printStackTrace();
      }
    }
  } // GEN-LAST:event_jButton3ActionPerformed
Example #4
0
 private void jButton2ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed
   // TODO add your handling code here:
   modelolistaNome.clear();
   ResultSet rs = null;
   ConectarAOBanco cd = new ConectarAOBanco();
   String id = jTextField1.getText();
   String query = "SELECT nome FROM universidade.professor WHERE id = '" + id + "' ORDER BY nome";
   cd.ConectarBanco();
   rs = cd.query(query);
   int resultado;
   try {
     resultado = exibirResultado(rs);
     if (resultado == 1) {
       jList1.setModel(modelolistaNome);
     } else {
       JOptionPane.showMessageDialog(this, "Professor não foi encontrado");
     }
   } catch (SQLException sqlex) {
     sqlex.printStackTrace();
   }
 } // GEN-LAST:event_jButton2ActionPerformed