private void jButton2ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed Conecta CN = new Conecta(); if (jComboBox1.getSelectedItem() == "Gerente") { String Str = "INSERT INTO Usuario VALUES ('" + jTextField1.getText() + "','" + jTextField2.getText() + "',1);"; boolean b = CN.InsereSQL(Str); if (b) { JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!"); } } else if (jComboBox1.getSelectedItem() == "Consultador") { String Str = "INSERT INTO Usuario VALUES ('" + jTextField1.getText() + "','" + jTextField2.getText() + "',2);"; boolean b = CN.InsereSQL(Str); if (b) { JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!"); jTextField1.setText(""); jTextField2.setText(""); } } else if (jComboBox1.getSelectedItem() == "Alterador") { String Str = "INSERT INTO Usuario VALUES ('" + jTextField1.getText() + "','" + jTextField2.getText() + "',3);"; boolean b = CN.InsereSQL(Str); if (b) { JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!"); jTextField1.setText(""); jTextField2.setText(""); } } else if (jComboBox1.getSelectedItem() == "Técnico") { String Str = "INSERT INTO Usuario VALUES ('" + jTextField1.getText() + "','" + jTextField2.getText() + "',4);"; boolean b = CN.InsereSQL(Str); if (b) { JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!"); jTextField1.setText(""); jTextField2.setText(""); } } } // GEN-LAST:event_jButton2ActionPerformed
public List<Depto> listarDeptos() { List lista = new ArrayList<Depto>(); try { Connection con = Conecta.getConexao(); String sql = "SELECT * FROM departamentos ORDER BY NomeDepto"; PreparedStatement pstmt = con.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { Depto d = new Depto(); d.setNumDepto(rs.getInt("NúmDepto")); d.setNomeDepto(rs.getString("NomeDepto")); d.setNomeCentro(rs.getString("NomeCentro")); lista.add(d); } } catch (Exception e) { return null; } return lista; }
public Alerta() { con = Conecta.getInstance(); }