예제 #1
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);
    }
  }
예제 #2
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();
  }