Esempio n. 1
0
 public void inserir(Usuario usuario) {
   try {
     Connection conexao = getConnection();
     PreparedStatement pstm =
         conexao.prepareStatement(
             "Insert into usuario (login, senha, nome, cpf, email) values (?,?,?,?,?)");
     pstm.setString(1, usuario.getLogin());
     pstm.setString(2, usuario.getSenha());
     pstm.setString(3, usuario.getNome());
     pstm.setString(4, usuario.getCpf());
     pstm.setString(5, usuario.getEmail());
     pstm.execute();
     pstm.close();
     conexao.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  public void alterar(Usuario usuario) {
    try {
      Connection conexao = getConnection();

      PreparedStatement pstmt =
          conexao.prepareStatement(
              "update usuario set nome = ?, cpf = ?, email = ?, senha = ?" + " WHERE login = ? ");
      pstmt.setString(1, usuario.getNome());
      pstmt.setString(2, usuario.getCpf());
      pstmt.setString(3, usuario.getEmail());
      pstmt.setString(4, usuario.getSenha());
      pstmt.execute();
      pstmt.close();
      conexao.close();

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