示例#1
0
  public ArrayList DeletaFrag(String codCategoria, String codigoFrag, String codigoCurso)
      throws SQLException {
    ArrayList listaFrag = new ArrayList();
    Connection con = null;
    PreparedStatement psmt = null;

    String query =
        "Delete From fragilidades WHERE codfragilidade='"
            + codigoFrag
            + "' AND codCurso='"
            + codigoCurso
            + "' AND codCategoria='"
            + codCategoria
            + "' ";

    try {
      con = Conexao.getConnection();
      psmt = con.prepareStatement(query.toString());

      psmt.executeUpdate(query);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      psmt.close();
      psmt = null;
      con.close();
      con = null;
    }
    return listaFrag;
  }
示例#2
0
  public static void UpdateCliente(Cliente cli, int id) {

    PreparedStatement stmt;

    try {
      String sql =
          ("UPDATE tabcliente SET empresa='"
              + cli.getEmpresa()
              + "' , cnpj='"
              + cli.getCnpj()
              + "', setor='"
              + cli.getSetor()
              + "', contato='"
              + cli.getContato()
              + "' where idCliente = '"
              + id
              + "';");

      stmt = Conexao.getConnection().prepareStatement(sql);
      stmt.executeUpdate();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao Alterar os dados do Cliente: ", ex);
    }
  }
示例#3
0
  public ArrayList InsertFrag(
      String login,
      String senha,
      String codCurso,
      String codCategoria,
      String codigoFrag,
      String texto,
      String texto2,
      String prazo,
      String responsavel)
      throws SQLException {
    ArrayList listaFrag = new ArrayList();
    Connection con = null;
    PreparedStatement psmt = null;

    texto = texto.replaceAll("'", "\"");
    texto2 = texto2.replaceAll("'", "\"");

    String query =
        "INSERT INTO fragilidades(login,senha,codCurso,codCategoria,codfragilidade,textoFragilidade,proposta,prazo,responsavel) VALUES('"
            + login
            + "','"
            + senha
            + "','"
            + codCurso
            + "','"
            + codCategoria
            + "','"
            + codigoFrag
            + "','"
            + texto
            + "','"
            + texto2
            + "','"
            + prazo
            + "','"
            + responsavel
            + "')";

    try {
      con = Conexao.getConnection();
      psmt = con.prepareStatement(query.toString());

      psmt.executeUpdate(query);

    } catch (Exception e) {
      erro = "Erro: " + query;
    } finally {
      psmt.close();
      psmt = null;
      con.close();
      con = null;
    }
    return listaFrag;
  }
示例#4
0
  public List<Equipamento> getAll() {
    List<Equipamento> lista = new ArrayList<Equipamento>();
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = Conexao.getConnection();
      String sql =
          "select codigo, descricao, datafabricacao, marca, modelo, fornecedor, tipo, observacoes from equipamento";
      ps = conn.prepareStatement(sql);

      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        Integer codigo = rs.getInt(1);
        String descricao = rs.getString(2);
        Date datafabricacao = rs.getDate(3);
        String marca = rs.getString(4);
        String modelo = rs.getString(5);
        Integer fornecedor = rs.getInt(6);
        String tipo = rs.getString(7);
        String observacao = rs.getString(8);

        Equipamento e = new Equipamento();
        e.setEqp_codigo(codigo);
        e.setEqp_descricao(descricao);
        e.setEqp_dtfabricacao(datafabricacao);
        e.setEqp_marca(marca);
        e.setEqp_modelo(modelo);
        int for_codigo = 0;
        e.setFor_codigo(for_codigo);
        int eqp_tipo = 0;
        e.setEqp_tipo(eqp_tipo);
        e.setEqp_obs(tipo);

        lista.add(e);
      }
    } catch (SQLException e) {
      System.out.println("ERRO: " + e.getMessage());
    } finally {
      if (ps != null) {
        try {
          ps.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
    }
    return lista;
  }
示例#5
0
  public Equipamento getEquipamento(Integer codigo) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = Conexao.getConnection();
      String sql =
          "select codigo, descricao, datafabricacao, marca, modelo, fornecedor, tipo, observacoes from equipamento where codigo = ?";

      // pesquisa
      ps = conn.prepareStatement(sql);
      ps.setInt(1, codigo);

      // resultado
      ResultSet rs = ps.executeQuery();
      if (rs.next()) {
        Integer cod = rs.getInt(1);
        String descricao = rs.getString(2);
        Date datafabricacao = rs.getDate(3);
        String marca = rs.getString(4);
        String modelo = rs.getString(5);
        Integer fornecedor = rs.getInt(6);
        String tipo = rs.getString(7);
        String observacoes = rs.getString(8);

        Equipamento e = new Equipamento();
        e.setEqp_codigo(cod);
        e.setEqp_descricao(descricao);
        e.setEqp_dtfabricacao(datafabricacao);
        e.setEqp_marca(marca);
        e.setEqp_modelo(modelo);

        return e;
      }
    } catch (SQLException e) {
      System.out.println("ERRO: " + e.getMessage());
    } finally {
      if (ps != null) {
        try {
          ps.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
    }
    return null;
  }
public class UsuarioDAO {
  private Connection con = Conexao.getConnection();

  public void Cadastrar(Usuario usuario) {

    String sql = "insert into usuario (nome,login,email,senha)values (?,?,?,?)";
    try {
      // prepared statement para inserção
      PreparedStatement stmt = con.prepareStatement(sql);

      // seta os valores
      stmt.setString(1, usuario.getNome());
      stmt.setString(2, usuario.getLogin());
      stmt.setString(3, usuario.getEmail());
      stmt.setString(4, usuario.getSenha());

      // executa
      stmt.execute();
      stmt.close();
      System.out.println("Cadastrado com sucesso!");
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }

  public String Verificar(Usuario usuario) {
    String userName = null;
    String passwrd = null;
    String sql = "select login,senha from usuario where senha = ?";
    try {
      PreparedStatement stmt = con.prepareStatement(sql);
      stmt.setString(1, usuario.getSenha());
      ResultSet rs = stmt.executeQuery();
      if (rs != null && rs.next()) {
        userName = rs.getString("login");
        passwrd = rs.getString("senha");
      }

      rs.close();
      stmt.close();
      con.close();
    } catch (Exception e) {
      System.out.println("Exception is :" + e);
    }
    if (usuario.getLogin().equals(userName) && usuario.getSenha().equals(passwrd)) {
      return ("Welcome " + usuario.getLogin());
    } else {
      return ("Invalid username or password,please try again");
    }
  }
}
示例#7
0
  public ArrayList InsertPot(
      String login,
      String senha,
      String codCurso,
      String codCategoria,
      String codPotencialidade,
      String textoProposta,
      String tipoPot)
      throws SQLException {
    ArrayList listaPot = new ArrayList();
    Connection con = null;
    PreparedStatement psmt = null;

    textoProposta = textoProposta.replaceAll("'", "\"");

    String query =
        "INSERT INTO potencialidades(login,senha,codCurso,codCategoria,codPotencialidade,textoProposta, tipoPot) VALUES('"
            + login
            + "','"
            + senha
            + "','"
            + codCurso
            + "','"
            + codCategoria
            + "','"
            + codPotencialidade
            + "','"
            + textoProposta
            + "','"
            + tipoPot
            + "')";

    try {
      con = Conexao.getConnection();
      psmt = con.prepareStatement(query.toString());

      psmt.executeUpdate(query);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {

      psmt.close();
      psmt = null;
      con.close();
      con = null;
    }
    return listaPot;
  }
示例#8
0
  public void insert(Equipamento equipamento) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = Conexao.getConnection();
      String sql =
          "insert into equipamento (codigo, descricao, datafabricacao, marca, modelo, fornecedor, tipo, observacoes) "
              + "values(?,?,?,?,?,?,?,?)";
      ps = conn.prepareStatement(sql);
      ps.setInt(1, equipamento.getEqp_codigo());
      ps.setString(2, equipamento.getEqp_descricao());
      ps.setString(3, equipamento.getEqp_marca());
      ps.setString(4, equipamento.getEqp_modelo());
      ps.setInt(5, equipamento.getUsu_codigo());
      ps.setInt(6, equipamento.getEqp_tipo());
      ps.setString(2, equipamento.getEqp_obs());
      ps.execute();

      conn.commit();

    } catch (SQLException e) {
      System.out.println("ERRO: " + e.getMessage());

      if (conn != null) {
        try {
          conn.rollback();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }

    } finally {
      if (ps != null) {
        try {
          ps.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
    }
  }
示例#9
0
  public static void ExcluirCliente(int id) {

    CallableStatement stmt;
    try {
      stmt = Conexao.getConnection().prepareCall("{call ExcluirCliente(?)}");

      stmt.setInt(1, id);

      stmt.execute();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao excluir os dados do Cliente: ", ex);
    }
  }
示例#10
0
  public static void ExcluirLembrete(int id) { // se tiver mais de um lembrete ver

    PreparedStatement stmt;
    try {

      String sql = ("DELETE FROM tablembrete WHERE idLembrete = ?; ");

      stmt = Conexao.getConnection().prepareStatement(sql);
      stmt.setInt(1, id);
      stmt.execute();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao excluir os dados do Cliente: ", ex);
    }
  }
示例#11
0
  public static ArrayList CarregaCliente(int id) {

    Statement stmt;
    ArrayList<Cliente> cliente = new ArrayList<Cliente>();

    try {
      String Sql =
          "SELECT * FROM tabcliente cli\n"
              + "INNER JOIN tabtel tel\n"
              + "INNER JOIN tabemail email\n"
              + "INNER JOIN tabcontato cont\n"
              + "ON cont.id_contato = cli.tabContato_id_contato AND\n"
              + "cont.id_contato = tel.contato_id AND\n"
              + "id_contato = email.contato_id_contato where cli.idcliente = '"
              + id
              + "';";

      ResultSet rs;
      stmt = Conexao.getConnection().createStatement();
      rs = stmt.executeQuery(Sql);

      while (rs.next()) {
        Cliente c = new Cliente();

        c.setId(rs.getInt("idcliente"));
        c.setEmpresa((rs.getString("empresa")));
        c.setCnpj(rs.getString("cnpj"));
        c.setContato(rs.getString("contato"));
        c.setSetor(rs.getString("setor"));
        c.setTel(rs.getString("telefone"));
        c.setEmail(rs.getString("email"));
        c.setIdContato(rs.getInt("tabContato_id_contato"));
        c.setId(id);
        cliente.add(c);
      }
      rs.close();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao excluir os dados do Cliente: ", ex);
    }
    return cliente;
  }
示例#12
0
  public static void CadLembrete(Lembrete lembrete) {

    PreparedStatement stmt;
    try {
      String sql =
          ("INSERT INTO tablembrete (dataContato,hora,descricao,tabCliente_idcliente) VALUES(?,?,?,?)");
      stmt = Conexao.getConnection().prepareStatement(sql);

      stmt.setDate(1, (Date) lembrete.getDataLembrete());
      stmt.setTime(2, lembrete.getHora());
      stmt.setString(3, lembrete.getDescricao());
      stmt.setInt(4, lembrete.getCodCliente());

      stmt.executeUpdate();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao Cadastrar Lembrete: ", ex);
    }
  }
示例#13
0
  public void delete(Equipamento equipamento) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = Conexao.getConnection();
      String sql = "delete from equipamento where codigo = ?";
      ps = conn.prepareStatement(sql);
      ps.setInt(1, equipamento.getEqp_codigo());
      ps.execute();

      conn.commit();
    } catch (SQLException e) {
      System.out.println("ERRO: " + e.getMessage());

      if (conn != null) {
        try {
          conn.rollback();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }

    } finally {
      if (ps != null) {
        try {
          ps.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException ex) {
          System.out.println("ERRO: " + ex.getMessage());
        }
      }
    }
  }
示例#14
0
  public static void CadCliente(Cliente cli) {

    PreparedStatement stmt;
    try {
      String sql =
          ("INSERT INTO tabcliente(usuario_id_usuario, tabContato_id_contato,empresa,cnpj,setor,contato)  VALUES(?,?,?,?,?,?)");
      stmt = Conexao.getConnection().prepareStatement(sql);

      stmt.setInt(1, 3);
      stmt.setInt(2, cli.getIdContato());
      stmt.setString(3, cli.getEmpresa());
      stmt.setString(4, cli.getCnpj());
      stmt.setString(5, cli.getSetor());
      stmt.setString(6, cli.getContato());

      stmt.executeUpdate();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao Cadastrar Cliente: ", ex);
    }
  }
示例#15
0
  public static int idContato(int id) {

    Statement stmt;
    Cliente c = new Cliente();

    try {
      String Sql = "SELECT  tabContato_id_contato FROM tabcliente WHERE idcliente = '" + id + "';";

      ResultSet rs;
      stmt = Conexao.getConnection().createStatement();
      rs = stmt.executeQuery(Sql);

      while (rs.next()) {
        c.setIdContato(rs.getInt("tabContato_id_contato"));
      }
      rs.close();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao excluir os dados do Cliente: ", ex);
    }
    return c.getIdContato();
  }
示例#16
0
  public static ArrayList CarregaLembrete(int id) {

    Statement stmt;
    ArrayList<Lembrete> lembretes = new ArrayList<Lembrete>();

    try {
      String Sql =
          "select idLembrete, dataContato, hora, descricao, tabCliente_idcliente "
              + "from tablembrete inner join tabcliente on idcliente = tabCliente_idcliente "
              + "where idcliente = '"
              + id
              + "';";

      ResultSet rs;
      stmt = Conexao.getConnection().createStatement();
      rs = stmt.executeQuery(Sql);

      while (rs.next()) {
        Lembrete l = new Lembrete();

        l.setIdLembrete(rs.getInt("idLembrete"));
        l.setDataLembrete((rs.getDate("dataContato")));
        l.setHora(rs.getTime("hora"));
        l.setDescricao(rs.getString("descricao"));
        l.setCodCliente(rs.getInt("tabCliente_idcliente"));
        lembretes.add(l);
      }
      rs.close();
      stmt.close();

    } catch (SQLException ex) {
      Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
      throw new RuntimeException("Erro ao excluir os dados do Cliente: ", ex);
    }
    return lembretes;
  }
示例#17
0
  public ArrayList UpdateFrag(
      int permissao,
      String login,
      String senha,
      String codCurso,
      String codCategoria,
      String codigoFrag,
      String texto,
      String texto2,
      String prazo,
      String responsavel)
      throws SQLException {
    ArrayList listaFrag = new ArrayList();
    Connection con = null;
    PreparedStatement psmt = null;

    texto = texto.replaceAll("'", "\"");
    texto2 = texto2.replaceAll("'", "\"");

    String query = "";

    if (permissao == 10 || permissao == 1) {
      query =
          "UPDATE fragilidades SET codCurso='"
              + codCurso
              + "',codCategoria='"
              + codCategoria
              + "',codfragilidade='"
              + codigoFrag
              + "',textoFragilidade='"
              + texto
              + "',proposta='"
              + texto2
              + "',prazo='"
              + prazo
              + "',responsavel='"
              + responsavel
              + "' WHERE codfragilidade='"
              + codigoFrag
              + "' AND codCategoria='"
              + codCategoria
              + "' AND codCurso='"
              + codCurso
              + "'";
    } else {
      query =
          "UPDATE fragilidades SET login='******',senha='"
              + senha
              + "',codCurso='"
              + codCurso
              + "',codCategoria='"
              + codCategoria
              + "',codfragilidade='"
              + codigoFrag
              + "',textoFragilidade='"
              + texto
              + "',proposta='"
              + texto2
              + "',prazo='"
              + prazo
              + "',responsavel='"
              + responsavel
              + "' WHERE codfragilidade='"
              + codigoFrag
              + "' AND codCategoria='"
              + codCategoria
              + "' AND codCurso='"
              + codCurso
              + "'";
    }

    try {
      con = Conexao.getConnection();
      psmt = con.prepareStatement(query.toString());

      psmt.executeUpdate(query);

    } catch (Exception e) {
      erro = "Erro: " + query;
    } finally {
      psmt.close();
      psmt = null;
      con.close();
      con = null;
    }
    return listaFrag;
  }
示例#18
0
  public ArrayList Grava(String codigoCat, String grava, int CodigoCurso) throws SQLException {

    ArrayList listaGrava = new ArrayList();
    Connection con = null;
    PreparedStatement psmt = null;
    ResultSet rs = null;
    String query = null;

    ///// se for uma potencialidade/////////////
    if (grava.equals("Gravar Potencialidade")) {

      query =
          "SELECT * FROM potencialidades WHERE codCategoria="
              + codigoCat
              + " AND codCurso="
              + CodigoCurso
              + " ORDER BY codPotencialidade";
    }
    ///// se for uma fragilidade/////////////
    if (grava.equals("Gravar Fragilidade")) {

      query =
          "SELECT * FROM fragilidades WHERE codCategoria="
              + codigoCat
              + " AND codCurso="
              + CodigoCurso
              + " ORDER BY codfragilidade";
    }

    try {
      con = Conexao.getConnection();
      psmt = con.prepareStatement(query.toString());
      rs = psmt.executeQuery();

      while (rs.next()) {

        ///// se for uma potencialidade/////////////
        if (grava.equals("Gravar Potencialidade")) {

          PotencialidadesVO vo = new PotencialidadesVO();
          vo.setCodPotencialidade(rs.getInt("codPotencialidade"));
          listaGrava.add(vo);
        }
        ///// se for uma fragilidade/////////////
        if (grava.equals("Gravar Fragilidade")) {

          FragilidadesVO vo = new FragilidadesVO();
          vo.setCodfragilidade(rs.getInt("codfragilidade"));
          listaGrava.add(vo);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      rs.close();
      rs = null;
      psmt.close();
      psmt = null;
      con.close();
      con = null;
    }

    return listaGrava;
  }
示例#19
0
  public ArrayList UpdatePot(
      int permissao,
      String login,
      String senha,
      String codCurso,
      String codCategoria,
      String codPotencialidade,
      String textoProposta,
      String tipoPot)
      throws SQLException {
    ArrayList listaPot = new ArrayList();
    Connection con = null;
    PreparedStatement psmt = null;

    textoProposta = textoProposta.replaceAll("'", "\"");

    String query = "";

    if (permissao == 10 || permissao == 1) {
      query =
          "UPDATE potencialidades SET codCurso='"
              + codCurso
              + "',codCategoria='"
              + codCategoria
              + "',codPotencialidade='"
              + codPotencialidade
              + "',textoProposta='"
              + textoProposta
              + "',tipoPot='"
              + tipoPot
              + "' WHERE codPotencialidade='"
              + codPotencialidade
              + "' AND codCategoria='"
              + codCategoria
              + "' AND codCurso='"
              + codCurso
              + "' ";

    } else {
      query =
          "UPDATE potencialidades SET login='******',senha='"
              + senha
              + "',codCurso='"
              + codCurso
              + "',codCategoria='"
              + codCategoria
              + "',codPotencialidade='"
              + codPotencialidade
              + "',textoProposta='"
              + textoProposta
              + "',tipoPot='"
              + tipoPot
              + "' WHERE codPotencialidade='"
              + codPotencialidade
              + "' AND codCategoria='"
              + codCategoria
              + "' AND codCurso='"
              + codCurso
              + "' ";
    }

    try {
      con = Conexao.getConnection();
      psmt = con.prepareStatement(query.toString());

      psmt.executeUpdate(query);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      psmt.close();
      psmt = null;
      con.close();
      con = null;
    }
    return listaPot;
  }