Exemple #1
0
  /**
   * Funcao que carrega uma lista de julgamentos com as notas finais
   *
   * @param Julgamento_model julgamentoModel
   * @return ArrayList<Julgamento_model>
   */
  public static ArrayList<Julgamento_model> listarNotasFinais(int idAtletaDisputa, int limit) {

    ArrayList<Julgamento_model> listaJulgamento = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet res = null;
    String limitString = "";

    try {

      conn = BDConexao_dao.conectar();

      if (limit > 0) {
        String valor = Integer.toString(limit);
        limitString = "LIMIT " + valor;
      }

      String sql =
          "SELECT "
              + "j.*,"
              + "o.*,"
              + "ROUND((SUM(`bodyboardsys`.j.`nota`)/3), 2) as ondanotafinal "
              + "FROM "
              + "`bodyboardsys`.`julgamento` j "
              + "JOIN `bodyboardsys`.`ondas` o ON(`bodyboardsys`.o.`idondas` = `bodyboardsys`.j.`idonda`) "
              + "WHERE "
              + "`bodyboardsys`.j.`idonda` in( SELECT idondas FROM `bodyboardsys`.`ondas` where idatletadisputa = '"
              + idAtletaDisputa
              + "' ) "
              + "GROUP BY "
              + "`bodyboardsys`.j.`idonda` "
              + "ORDER BY "
              + "ondanotafinal DESC "
              + limitString
              + ";";

      stmt = (Statement) conn.createStatement();

      res = stmt.executeQuery(sql);

    } catch (SQLException e) {

      try {

        conn.close();
        System.out.println("Erro ao conectar com o banco: " + e.getMessage());
        System.err.println("SQLException: " + e.getMessage());
        System.err.println("SQLState: " + e.getSQLState());
        System.err.println("VendorError: " + e.getErrorCode());

        return null;

      } catch (SQLException e2) {

        System.out.println("Erro ao conectar com o banco: " + e.getMessage());
        System.err.println("SQLException: " + e.getMessage());
        System.err.println("SQLState: " + e.getSQLState());
        System.err.println("VendorError: " + e.getErrorCode());

        return null;
      }
    }

    try {

      // crio a lista
      JulgamentoController julgamentoControl = new JulgamentoController();
      listaJulgamento = julgamentoControl.carregarListaNotasFinaisResultSet(res);

      // fecho a conexao do BD
      conn.close();

      return listaJulgamento;

    } catch (Exception e) {
      return null;
    }
  }
Exemple #2
0
  /**
   * Funcao que carrega uma lista de julgamentos
   *
   * @param Julgamento_model julgamentoModel
   * @param String ordenar
   * @return ArrayList<Julgamento_model>
   */
  public static ArrayList<Julgamento_model> listarJulgamento(
      Julgamento_model julgamentoModel, String ordenar) {

    ArrayList<Julgamento_model> listaJulgamento = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet res = null;

    // Filtro da minha query
    String filtro = "";
    String join = "";
    String ordem = "";

    try {

      if (ordenar != null) {
        ordem += BDConexao_dao.adicionaOrdem(ordem, ordenar, "ASC");
      }

      if (julgamentoModel.getIdjulgamento() != 0) {

        String valor = " idjulgamento=";
        valor += Integer.toString(julgamentoModel.getIdjulgamento());
        filtro += BDConexao_dao.adicionaFiltro(filtro, valor, "");
      }

      if (julgamentoModel.getJuizBateriaModel() != null) {

        if (julgamentoModel.getJuizBateriaModel().getIdjuizbateria() != 0) {

          String valor = " idjuizbateria=";
          valor += Integer.toString(julgamentoModel.getJuizBateriaModel().getIdjuizbateria());
          filtro += BDConexao_dao.adicionaFiltro(filtro, valor, "");
        }
      }

      conn = BDConexao_dao.conectar();

      String sql = "SELECT * FROM `bodyboardsys`.`julgamento` " + filtro + " " + ordem + ";";

      stmt = (Statement) conn.createStatement();

      res = stmt.executeQuery(sql);

    } catch (SQLException e) {

      try {
        // dou um rollback no BD caso ocorra alguma excessao ao inserir o Campeonato
        conn.rollback();
        conn.close();
        System.out.println("Erro ao conectar com o banco: " + e.getMessage());
        System.err.println("SQLException: " + e.getMessage());
        System.err.println("SQLState: " + e.getSQLState());
        System.err.println("VendorError: " + e.getErrorCode());

        return null;

      } catch (SQLException e2) {

        System.out.println("Erro ao conectar com o banco: " + e.getMessage());
        System.err.println("SQLException: " + e.getMessage());
        System.err.println("SQLState: " + e.getSQLState());
        System.err.println("VendorError: " + e.getErrorCode());

        return null;
      }
    }

    try {

      // crio a lista
      JulgamentoController julgamentoControl = new JulgamentoController();
      listaJulgamento = julgamentoControl.carregarListaJulgamento(res);

      // fecho a conexao do BD
      conn.close();

      return listaJulgamento;

    } catch (Exception e) {
      return null;
    }
  }