Example #1
1
  public Album getAlbum(Integer idAlbum) throws ListAlbumException {
    Album album = new Album();

    try {
      Context ctx = new InitialContext();
      DataSource source = (DataSource) ctx.lookup("jdbc/MusicStore");
      connexion = source.getConnection();

      String requeteSQL =
          "SELECT Album.idAlbum, Album.titre, Album.prix, Album.image, Artiste.nom, Label.Nom, Label.Image, "
              + " CASE WHEN Promotion_Artiste.idArtiste = Artiste.idArtiste "
              + "     THEN true "
              + "     ELSE false "
              + " END, "
              + " CASE WHEN Promotion_Artiste.idArtiste = Artiste.idArtiste "
              + "     THEN (Album.Prix - (Album.Prix * Promotion.prcremise * 0.01))"
              + " END,"
              + " CASE WHEN Promotion_Artiste.idArtiste = Artiste.idArtiste "
              + "     THEN Promotion.prcremise"
              + " END,"
              + " Artiste.idartiste "
              + " FROM ALBUM,ARTISTE,PROMOTION,PROMOTION_ARTISTE,ARTISTE_ALBUM,LABEL"
              + " WHERE ALBUM.IDALBUM = ARTISTE_ALBUM.IDALBUM AND ARTISTE_ALBUM.IDARTISTE = ARTISTE.IDARTISTE "
              + " AND ALBUM.IDALBUM = ? AND LABEL.IDLABEL=ALBUM.IDLABEL"
              + " AND Promotion_Artiste.idPromotion = Promotion.idPromotion AND Promotion.datedeb <= current_date AND Promotion.datefin >= current_date";

      PreparedStatement prepStat = connexion.prepareStatement(requeteSQL);
      prepStat.setInt(1, idAlbum);
      ResultSet donnees = prepStat.executeQuery();

      if (donnees.next()) {
        album.setIdAlbum(donnees.getInt(1));
        album.setTitre(donnees.getString(2));
        album.setPrix(donnees.getDouble(3));
        album.setImage(donnees.getString(4));
        album.setArtiste(donnees.getString(5));
        album.setLabel(donnees.getString(6));
        album.setLabelImg(donnees.getString(7));
        album.setPromo(donnees.getBoolean(8));
        album.setPrixPromo(donnees.getDouble(9));
        album.setPrcRemise(donnees.getInt(10));
        album.setIdArtiste(donnees.getInt(11));
      } else {
        throw new ListAlbumException(
            "albumNotExist"); // si aucun album trouvé, c'est que l'id n'existe pas
      }

      return album;
    } catch (SQLException e) {
      throw new ListAlbumException("sqlException");
    } catch (NamingException e) {
      throw new ListAlbumException("errorNaming");
    } finally {
      try {
        connexion.close();
      } catch (SQLException e) {
        throw new ListAlbumException("sqlException");
      }
    }
  }
 public Vector getDetalles(String codEstudiante, Object carrera) throws SQLException {
   Vector v = new Vector();
   ConexionDB conecta = new ConexionDB();
   con = conecta.GetConnection();
   PreparedStatement ps = con.prepareStatement(queryGetNotas);
   ps.setString(1, codEstudiante);
   ps.setObject(2, carrera);
   ResultSet rs = ps.executeQuery();
   fca_estudiante_materia estu;
   while (rs.next()) {
     estu = new fca_estudiante_materia();
     estu.setCODIGO_CARRERA(rs.getString(1));
     estu.setDESCRIPCION(rs.getString(2));
     estu.setNUMERO_PERIODO(rs.getInt(3));
     estu.setNUMERO_SEMESTRE(rs.getInt(4));
     estu.setCODIGO_PARALELO(rs.getString(5));
     estu.setCODIGO_MATERIA(rs.getString(6));
     estu.setNUMERO_AULA(rs.getString(7));
     estu.setID_ESTUDIANTE(rs.getString(8));
     estu.setVEZ_TOMADA(rs.getDouble(9));
     estu.setNOTA01(rs.getDouble(10));
     estu.setNOTA02(rs.getDouble(11));
     estu.setNOTA_RECUPERACION(rs.getDouble(12));
     estu.setPROMEDIO(rs.getDouble(13));
     estu.setMATERIA_APROBADA(rs.getString(14));
     estu.setANIO_MATERIA(rs.getString(15));
     estu.setASISTENCIA(rs.getInt(16));
     v.add(estu);
   }
   conecta.desconectar();
   return v;
 }
 @Override
 public Match mapRow(ResultSet rs, int rowNum) throws SQLException {
   Match match = new Match();
   match.setMatchId(rs.getInt("MATCH_ID"));
   match.setLeagueName(rs.getString("LEAGUE_NAME").trim());
   match.setLeagueId(rs.getInt("LEAGUE_ID"));
   match.setHomeTeamName(rs.getString("HOME_TEAM_NAME").trim());
   match.setAwayTeamName(rs.getString("AWAY_TEAM_NAME").trim());
   match.setHomeScore(rs.getInt("HOME_SCORE"));
   match.setAwayScore(rs.getInt("AWAY_SCORE"));
   match.setHomeTeamId(rs.getInt("HOME_TEAM_ID"));
   match.setAwayTeamId(rs.getInt("AWAY_TEAM_ID"));
   match.setFeedTypeId(rs.getInt("FEED_TYPE_ID"));
   match.setMatchTime(rs.getString("MATCH_TIME").trim());
   match.setRunningIndicator(rs.getInt("RUNNING_INDICATOR"));
   match.setTimeGameLive(rs.getString("TIME_GAME_LIVE").trim());
   match.setKoAwayPrice(rs.getDouble("KICK_OFF_AWAY_PRICE"));
   match.setKoDrawPrice(rs.getDouble("KICK_OFF_DRAW_PRICE"));
   match.setKoHomePrice(rs.getDouble("KICK_OFF_HOME_PRICE"));
   match.setKoOuHfPrice(rs.getDouble("KICK_OFF_OU_HF_PRICE"));
   match.setTimeFirstGoal(rs.getInt("TIME_FIRST_GOAL"));
   match.setMatchDate(new DateTime(rs.getDate("MATCH_DATE")));
   match.setBookieId(rs.getInt("BOOKIE_ID"));
   return match;
 }
 public ArrayList<DetalleFactura> buscar(Factura entidad) throws Exception {
   ArrayList<DetalleFactura> lista = new ArrayList<DetalleFactura>();
   try {
     cnn = Conexion.getConexion();
     CallableStatement cs = null;
     cs = cnn.prepareCall("call uspListDetalleFactrua(?)");
     cs.setInt(1, entidad.getIdFactura());
     rs = cs.executeQuery();
     while (rs.next()) {
       DetalleFactura objeto = new DetalleFactura();
       objeto.setIdDetalleFactura(rs.getInt("Iddetallefactura"));
       objeto.setIdProducto(rs.getInt("Idproducto"));
       objeto.setCantidad(rs.getInt("Cantidad"));
       objeto.setPrecio(rs.getDouble("Precio"));
       objeto.setSubTotal(rs.getDouble("Subtotal"));
       objeto.setIdFactura(rs.getInt("Idfactura"));
       objeto.setDProducto(rs.getString("DProducto"));
       lista.add(objeto);
     }
     cnn.close();
     cs.close();
   } catch (SQLException ex) {
     throw ex;
   }
   return lista;
 }
  /** 获取指定CPU ID的CPU利用率列表 */
  public List<CPUPerc> getPercsById(long id) {
    String sql = "select * from t_cpu_prec where prec_cpuid=?";
    List<CPUPerc> list = new ArrayList<CPUPerc>(20);
    try {
      super.doStart();
      pstmt = super.conn.prepareStatement(sql);
      pstmt.setLong(1, id);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        CPUPerc cp = new CPUPerc(rs.getLong("prec_timestamp"));
        cp.setIdle(rs.getDouble("prec_idle"));
        cp.setNice(rs.getDouble("prec_nice"));
        cp.setSys(rs.getDouble("prec_sys"));
        cp.setUser(rs.getDouble("prec_user"));
        cp.setWait(rs.getDouble("prec_wait"));
        cp.setCombined(rs.getDouble("prec_combined"));
        cp.setTimestamp(rs.getLong("prec_timestamp"));

        list.add(cp);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      DButil.getInstance().close(pstmt, rs);
    }
    return list;
  }
Example #6
1
  @Override
  public Set<EmpVO> getEmpsByDeptno(Integer deptno) {
    Set<EmpVO> set = new LinkedHashSet<EmpVO>();
    EmpVO empVO = null;

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {

      Class.forName(driver);
      con = DriverManager.getConnection(url, userid, passwd);
      pstmt = con.prepareStatement(GET_Emps_ByDeptno_STMT);
      pstmt.setInt(1, deptno);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        empVO = new EmpVO();
        empVO.setEmpno(rs.getInt("empno"));
        empVO.setEname(rs.getString("ename"));
        empVO.setJob(rs.getString("job"));
        empVO.setHiredate(rs.getDate("hiredate"));
        empVO.setSal(rs.getDouble("sal"));
        empVO.setComm(rs.getDouble("comm"));
        empVO.setDeptno(rs.getInt("deptno"));
        set.add(empVO); // Store the row in the vector
      }

      // Handle any driver errors
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Couldn't load database driver. " + e.getMessage());
      // Handle any SQL errors
    } catch (SQLException se) {
      throw new RuntimeException("A database error occured. " + se.getMessage());
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException se) {
          se.printStackTrace(System.err);
        }
      }
      if (pstmt != null) {
        try {
          pstmt.close();
        } catch (SQLException se) {
          se.printStackTrace(System.err);
        }
      }
      if (con != null) {
        try {
          con.close();
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }
    }
    return set;
  }
    public DetailedAccountStatementItem mapRow(ResultSet rs, int rowNum) throws SQLException {
      DetailedAccountStatementItem item = new DetailedAccountStatementItem();

      item.setId(rs.getInt("id"));
      item.setMarketId(rs.getInt("market_id"));
      item.setMarketName(rs.getString("market_name"));
      item.setMarketType(rs.getString("market_type"));
      item.setFullMarketName(rs.getString("full_market_name"));

      item.setSelectionId(rs.getInt("selection_id"));
      item.setSelectionName(rs.getString("selection_name"));

      item.setBetId(rs.getLong("bet_id"));

      item.setEventTypeId(rs.getInt("event_type_id"));
      item.setBetCategoryType(rs.getString("bet_category_type"));
      item.setBetType(rs.getString("bet_type"));
      item.setBetSize(rs.getDouble("bet_size"));
      item.setAvgPrice(rs.getDouble("avg_price"));
      item.setPlacedDate(rs.getTimestamp("placed_date"));
      item.setStartDate(rs.getTimestamp("start_date"));
      item.setSettledDate(rs.getTimestamp("settled_date"));
      item.setAmount(rs.getDouble("amount"));
      item.setCommission(rs.getBoolean("commission"));

      item.setStateMachineId(rs.getString("state_machine_id"));
      item.setStateName(rs.getString("state_name"));

      return item;
    }
Example #8
1
 public static List<PriceBar> getPriceDatas(
     String sym,
     java.util.Date beginDT,
     java.util.Date endDT,
     int priceMagnifier,
     int multiplier) {
   List<PriceBar> priceDatas = new ArrayList<PriceBar>();
   try {
     PreparedStatement datedRangeBySymbol =
         DBopsMySql.datedRangeBySymbol(
             sym, new Timestamp(beginDT.getTime()), new Timestamp(endDT.getTime()));
     ResultSet res = datedRangeBySymbol.executeQuery();
     while (res.next()) {
       PriceBar priceBar =
           new PriceBar(
               res.getTimestamp("datetime").getTime(),
               res.getDouble("open") / priceMagnifier * multiplier,
               res.getDouble("high") / priceMagnifier * multiplier,
               res.getDouble("low") / priceMagnifier * multiplier,
               res.getDouble("close") / priceMagnifier * multiplier,
               res.getLong("volume"));
       priceDatas.add(priceBar);
     }
     // int i = 1;
   } catch (SQLException ex) {
     MsgBox.err2(ex);
   } catch (Exception ex) {
     MsgBox.err2(ex);
   } finally {
     return priceDatas;
   }
 }
Example #9
0
 private List<BusRecRoute> getRec(ResultSet rset) {
   List<BusRecRoute> list = new ArrayList<BusRecRoute>();
   if (rset == null) return list;
   BusRecRoute rec;
   try {
     while (rset.next()) {
       rec = new BusRecRoute();
       rec.id = rset.getInt("id");
       rec.route_key = rset.getString("route_key");
       rec.curve_key = rset.getString("curve_key");
       rec.bus_type = rset.getInt("type");
       rec.company_id = rset.getInt("company_id");
       rec.company = rset.getString("company");
       rec.bus_line = rset.getString("bus_line");
       rec.rate_per_day = rset.getFloat("day");
       rec.rate_per_saturday = rset.getFloat("saturday");
       rec.rate_per_holiday = rset.getFloat("holiday");
       rec.remarks = rset.getString("remarks");
       rec.num = rset.getInt("num");
       rec.max_lat = rset.getDouble("max_lat");
       rec.min_lat = rset.getDouble("min_lat");
       rec.max_lon = rset.getDouble("max_lon");
       rec.min_lon = rset.getDouble("min_lon");
       list.add(rec);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return list;
 }
  public double[] getLatLong(String plaats) {
    if (plaats.contains("'") == true) {
      plaats = plaats.replaceAll("'", "''");
    }

    String query =
        "SELECT latitude,longitude FROM geocodes WHERE city = '" + plaats + "' ORDER BY id ";
    double[] resultArray = new double[2];

    try {
      Statement st = databaseConnection.createStatement();
      ResultSet rs = st.executeQuery(query);
      while (rs.next()) {
        Double lat = rs.getDouble("latitude");
        Double lon = rs.getDouble("longitude");
        resultArray[0] = lat;
        resultArray[1] = lon;
      }

      st.close();
      rs.close();
    } catch (SQLException ex) {
      System.err.println(ex.getMessage());
    }

    return resultArray;
  }
Example #11
0
  @Override
  public void read(DGuiSession session, int[] pk) throws SQLException, Exception {
    ResultSet resultSet = null;

    initRegistry();
    initQueryMembers();
    mnQueryResultId = DDbConsts.READ_ERROR;

    msSql = "SELECT * " + getSqlFromWhere(pk);
    resultSet = session.getStatement().executeQuery(msSql);
    if (!resultSet.next()) {
      throw new Exception(DDbConsts.ERR_MSG_REG_NOT_FOUND);
    } else {
      mnPkFormulaId = resultSet.getInt("id_frm");
      mnPkByProdId = resultSet.getInt("id_byp");
      mdQuantity = resultSet.getDouble("qty");
      mdMassUnit = resultSet.getDouble("mass_unt");
      mdMass_r = resultSet.getDouble("mass_r");
      mdBrix = resultSet.getDouble("brix");
      mdMassSolid_r = resultSet.getDouble("mass_sld_r");
      mbStandard = resultSet.getBoolean("b_std");
      mnFkItemId = resultSet.getInt("fk_itm");
      mnFkItemTypeId = resultSet.getInt("fk_itm_tp");
      mnFkUnitId = resultSet.getInt("fk_uom");

      readRegMembers(session, false);
      readXtaMembers(session);

      mbRegistryNew = false;
    }

    mnQueryResultId = DDbConsts.READ_OK;
  }
Example #12
0
  private CategoryDataset createDataset() {

    // row keys...
    final String series1 = "Closing Qty";
    final String series2 = "Issued Qty";
    final String series3 = "Received Qty";

    // column keys...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String dbUrl = "jdbc:mysql://localhost/ventura_enterpride";
    String query = "Select * from daily_stock";

    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con = DriverManager.getConnection(dbUrl, "root", "admin");
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(query);

      while (rs.next()) {
        dataset.addValue(rs.getDouble(2), series1, rs.getDate(3) + "Item Id :" + rs.getInt(8));
        dataset.addValue(rs.getDouble(4), series2, rs.getDate(3) + "Item Id :" + rs.getInt(8));
        dataset.addValue(rs.getDouble(6), series3, rs.getDate(3) + "Item Id :" + rs.getInt(8));
      } // end while

      con.close();
    } // end try
    catch (Exception e) {
      e.printStackTrace();
    }
    return dataset;
  }
  protected void upgradeRatingsStats() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer()) {
      StringBundler sb = new StringBundler(4);

      sb.append("select classNameId, classPK, count(1) as totalEntries,");
      sb.append(" sum(RatingsEntry.score) as totalScore, ");
      sb.append("sum(RatingsEntry.score) / count(1) as averageScore ");
      sb.append("from RatingsEntry group by classNameId, classPK");

      String selectSQL = sb.toString();

      String updateSQL =
          "update RatingsStats set totalEntries = ?, totalScore = ?, "
              + "averageScore = ? where classNameId = ? and classPK = ?";

      try (PreparedStatement ps1 = connection.prepareStatement(selectSQL);
          ResultSet rs = ps1.executeQuery();
          PreparedStatement ps2 =
              AutoBatchPreparedStatementUtil.autoBatch(connection.prepareStatement(updateSQL))) {

        while (rs.next()) {
          ps2.setInt(1, rs.getInt("totalEntries"));
          ps2.setDouble(2, rs.getDouble("totalScore"));
          ps2.setDouble(3, rs.getDouble("averageScore"));
          ps2.setLong(4, rs.getLong("classNameId"));
          ps2.setLong(5, rs.getLong("classPK"));

          ps2.addBatch();
        }

        ps2.executeBatch();
      }
    }
  }
    @Override
    public GearBoxOil mapRow(ResultSet rs, int rowNum) throws SQLException {
      GearBoxOil oil = new GearBoxOil();

      oil.setId(rs.getInt("id"));
      oil.setName(rs.getString("name"));
      oil.setDescription(rs.getString("description"));
      oil.setSpecification(rs.getString("Specification"));
      oil.setJudgement(rs.getDouble("judgement"));

      Manufacturer manufacturer = new Manufacturer();
      manufacturer.setId(rs.getInt("manufacturer"));
      manufacturer.setName(rs.getString("man_name"));
      oil.setManufacturer(manufacturer);

      OilStuff oilStuff = new OilStuff();
      oilStuff.setId(rs.getInt("oilStuff"));
      oilStuff.setName(rs.getString("os_name"));
      oil.setOilStuff(oilStuff);

      GearBoxType gearBoxType = new GearBoxType();
      gearBoxType.setId(rs.getInt("gearBoxType"));
      gearBoxType.setName(rs.getString("gbt_name"));
      oil.setGearBoxType(gearBoxType);

      oil.setPhoto(rs.getString("photo"));
      oil.setPrice(rs.getDouble("price"));
      oil.setValue(rs.getDouble("value"));
      oil.setViscosity(rs.getString("viscosity"));
      oil.setDiscount(rs.getDouble("discount"));
      oil.setInStock(rs.getInt("instock"));

      return oil;
    }
Example #15
0
  public ArrayList<Album> getRecherche(String artiste, String alb) throws AlbumException {
    try {
      ArrayList<Album> arrAlb = new ArrayList<Album>();
      Context ctx = new InitialContext();
      DataSource source = (DataSource) ctx.lookup("jdbc/MusicStore");
      connexion = source.getConnection();

      String requeteSQL =
          "SELECT Album.IDALBUM, Album.TITRE, Album.IMAGE, Artiste.NOM, Album.PRIX, Artiste.idArtiste, "
              + " CASE WHEN Promotion_Artiste.idArtiste = Artiste.idArtiste "
              + "     THEN true "
              + "     ELSE false "
              + " END, "
              + " CASE WHEN Promotion_Artiste.idArtiste = Artiste.idArtiste "
              + "     THEN (Album.Prix - (Album.Prix * Promotion.prcremise * 0.01))"
              + " END"
              + " FROM ALBUM,ARTISTE,PROMOTION,PROMOTION_ARTISTE,ARTISTE_ALBUM "
              + " WHERE ALBUM.IDALBUM = ARTISTE_ALBUM.IDALBUM AND ARTISTE_ALBUM.IDARTISTE = ARTISTE.IDARTISTE "
              + " AND Promotion_Artiste.idPromotion = Promotion.idPromotion AND Promotion.datedeb <= current_date AND Promotion.datefin >= current_date"
              + " AND UCASE(ALBUM.titre) like UCASE(?) And UCASE(Artiste.nom) like UCASE(?)";

      PreparedStatement prepStat = connexion.prepareStatement(requeteSQL);
      prepStat.setString(1, "%" + alb + "%");
      prepStat.setString(2, "%" + artiste + "%");
      ResultSet donnees;
      donnees = prepStat.executeQuery();

      while (donnees.next()) {
        Album album = new Album();

        album.setIdAlbum(donnees.getInt(1));
        album.setTitre(donnees.getString(2));
        album.setImage(donnees.getString(3));
        album.setArtiste(donnees.getString(4));
        album.setPrix(donnees.getDouble(5));
        album.setIdArtiste(donnees.getInt(6));
        album.setPromo(donnees.getBoolean(7));
        album.setPrixPromo(donnees.getDouble(8));

        arrAlb.add(album);
      }

      if (arrAlb.isEmpty()) {
        throw new AlbumException("noResult");
      }

      return arrAlb;
    } catch (SQLException ex) {
      throw new AlbumException(ex.toString());
      // throw new AlbumException("sqlException");
    } catch (NamingException ex) {
      throw new AlbumException("errorNaming");
    } finally {
      try {
        connexion.close();
      } catch (SQLException ex) {
        throw new AlbumException("sqlException");
      }
    }
  }
  @Override
  public ConsumedEnergy getConsumedEnergyById(int id) {
    String sql = "select * from  t_data_total_active_energy_consumed WHERE DEVICE_ID = ? LIMIT 1";

    Connection conn = null;

    try {
      conn = dataSource.getConnection();
      PreparedStatement ps = conn.prepareStatement(sql);
      ps.setInt(1, id);
      ConsumedEnergy consumedEnergy = null;
      ResultSet rs = ps.executeQuery();
      if (rs.next()) {
        consumedEnergy =
            new ConsumedEnergy(
                rs.getInt("DEVICE_ID"),
                rs.getDouble("MEASURE_VALUE"),
                rs.getDouble("MEASURE_V_DELTA"),
                rs.getTimestamp("MEASURE_TIMESTAMP"));
      }
      rs.close();
      ps.close();
      return consumedEnergy;
    } catch (SQLException e) {
      throw new RuntimeException(e);
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException e) {
        }
      }
    }
  }
  public VehicleType getVehicleType(String type_id) {
    try {
      global.openDBconnection();

      int type = Integer.parseInt(type_id);

      global.select_vehicle_type_where_id.setInt(1, type);

      ResultSet rs = global.select_vehicle_type_where_id.executeQuery();
      if (rs.next()) {
        int vehicles = 0;

        global.select_vehicle_where_type.setBoolean(1, true);
        global.select_vehicle_where_type.setInt(2, rs.getInt("id"));
        ResultSet rss = global.select_vehicle_where_type.executeQuery();
        while (rss.next()) {
          vehicles += 1;
        }

        return new VehicleType(
            rs.getInt("id"),
            rs.getString("name"),
            rs.getDouble("hour_rate"),
            rs.getDouble("day_rate"),
            vehicles);
      }

      return new VehicleType();
    } catch (Exception e) {
      System.out.println(e.getMessage());
      return new VehicleType();
    } finally {
      global.closeDBconnection();
    }
  }
 // metoda za pretragu po broju stanovnika
 public ArrayList<Country> SearchCountryPopulation(long Population) {
   ArrayList<Country> countries = new ArrayList<Country>();
   try {
     Connection connection = getConnected("world");
     PreparedStatement statement =
         connection.prepareStatement(
             "SELECT * FROM country WHERE Population <= " + Population + ";");
     ResultSet result = statement.executeQuery();
     while (result.next()) {
       countries.add(
           new Country(
               result.getString("Code"),
               result.getString("Name"),
               result.getString("Continent"),
               result.getString("Region"),
               result.getDouble("SurfaceArea"),
               result.getInt("IndepYear"),
               result.getLong("Population"),
               result.getDouble("LifeExpectancy"),
               result.getDouble("GNP"),
               result.getDouble("GNPOld"),
               result.getString("LocalName"),
               result.getString("GovernmentForm"),
               result.getString("HeadOfState"),
               result.getInt("Capital"),
               result.getString("Code2")));
     }
     connection.close();
   } catch (Exception e) {
     System.out.println(e.toString());
     return null;
   }
   return countries;
 }
Example #19
0
  public static Compra getCompra(Integer Id) {
    DAOCompra daocom = new DAOCompra();
    ResultSet rs = null;
    Compra comp = null;
    HashSet<ItemProdutoCompra> ItemProdutos = null;
    Fornecedor Fornecedor = null;
    Date dt_Compra = null;

    rs = daocom.getCompra(Id);

    try {
      while (rs.next()) {

        Fornecedor = CFornecedor.getFornecedor(rs.getInt(2));
        ItemProdutos = CItemProdutoCompra.getItemProdutos(Id);
        comp =
            new Compra(
                rs.getInt(1),
                ItemProdutos,
                Fornecedor,
                rs.getDate(3),
                rs.getDouble(4),
                rs.getDouble(5),
                rs.getDouble(6),
                rs.getDouble(7));
      }
    } catch (SQLException ex) {
      Logger.getLogger(CCompra.class.getName()).log(Level.SEVERE, null, ex);
    }

    return comp;
  }
Example #20
0
  /**
   * Method 'mapRow'
   *
   * @param rs
   * @param row
   * @throws SQLException
   * @return Po
   */
  public Po mapRow(ResultSet rs, int row) throws SQLException {
    Po dto = new Po();
    dto.setId(rs.getLong("po_code"));
    dto.setRateId(rs.getInt("rate_id"));
    dto.setPodate(rs.getDate("po_date"));
    dto.setSupplierCode(rs.getString("supplier_code"));
    dto.setDiscount(rs.getDouble("discount"));
    dto.setPph(rs.getDouble("pph"));
    dto.setPpn(rs.getDouble("ppn"));
    dto.setCurrency(rs.getString("currency"));
    /*dto.setCreatedby(rs.getString(8));
    dto.setCorpid(rs.getString(9));
    dto.setWhCode(rs.getString(10));
    dto.setDepartmentName(rs.getString(11));
    dto.setSupplierName(rs.getString(12));

    dto.setPrsremarks(rs.getString(14));
    dto.setRoleCode(rs.getString(15));
    dto.setStatus(rs.getString(16));
    dto.setStatusdate(rs.getDate(17));*/

    /*INSERT Currency Rate*/
    CurrencyRateDao currencyRateDao = DaoFactory.createCurrencyRateDao();
    CurrencyRate cr =
        currencyRateDao.findLatestByCurrencyCodeAndDate(dto.getCurrency(), dto.getPodate());
    dto.setCurrencyRate(cr);

    return dto;
  }
 /** 获取指定CPU ID和时间戳的CPU利用率 */
 public CPUPerc getCPUPercById(long id, long timestamp) {
   String sql = "select * from t_cpu_prec where prec_cpuid=? and prec_timestamp=?";
   CPUPerc cp = null;
   try {
     super.doStart();
     pstmt = super.conn.prepareStatement(sql);
     pstmt.setLong(1, id);
     pstmt.setLong(2, timestamp);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       cp = new CPUPerc(rs.getLong("prec_timestamp"));
       cp.setIdle(rs.getDouble("prec_idle"));
       cp.setNice(rs.getDouble("prec_nice"));
       cp.setSys(rs.getDouble("prec_sys"));
       cp.setUser(rs.getDouble("prec_user"));
       cp.setWait(rs.getDouble("prec_wait"));
       cp.setCombined(rs.getDouble("prec_combined"));
       cp.setTimestamp(rs.getLong("prec_timestamp"));
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     DButil.getInstance().close(pstmt, rs);
   }
   return cp;
 }
 @Override
 public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
   Map<String, Match> matches = new HashMap<String, Match>();
   Match match = null;
   String key = null;
   while (rs.next()) {
     match = new Match();
     match.setMatchId(rs.getInt("MATCH_ID"));
     match.setLeagueName(rs.getString("LEAGUE_NAME").trim());
     match.setLeagueId(rs.getInt("LEAGUE_ID"));
     match.setHomeTeamName(rs.getString("HOME_TEAM_NAME").trim());
     match.setAwayTeamName(rs.getString("AWAY_TEAM_NAME").trim());
     match.setHomeScore(rs.getInt("HOME_SCORE"));
     match.setAwayScore(rs.getInt("AWAY_SCORE"));
     match.setHomeTeamId(rs.getInt("HOME_TEAM_ID"));
     match.setAwayTeamId(rs.getInt("AWAY_TEAM_ID"));
     match.setFeedTypeId(rs.getInt("FEED_TYPE_ID"));
     match.setMatchTime(rs.getString("MATCH_TIME").trim());
     match.setRunningIndicator(rs.getInt("RUNNING_INDICATOR"));
     match.setTimeGameLive(rs.getString("TIME_GAME_LIVE").trim());
     match.setKoAwayPrice(rs.getDouble("KICK_OFF_AWAY_PRICE"));
     match.setKoDrawPrice(rs.getDouble("KICK_OFF_DRAW_PRICE"));
     match.setKoHomePrice(rs.getDouble("KICK_OFF_HOME_PRICE"));
     match.setKoOuHfPrice(rs.getDouble("KICK_OFF_OU_HF_PRICE"));
     match.setTimeFirstGoal(rs.getInt("TIME_FIRST_GOAL"));
     match.setMatchDate(new DateTime(rs.getDate("MATCH_DATE")));
     match.setBookieId(rs.getInt("BOOKIE_ID"));
     key = String.valueOf(match.getMatchId()) + "|" + rs.getString("NAME").trim();
     matches.put(key, match);
   }
   return matches;
 }
Example #23
0
  public ValoresAtualizaJob retornaNovosValores(Connection conn, JobLote job) throws SQLException {

    PreparedStatement stmt = null;
    ResultSet rs = null;
    ValoresAtualizaJob obj = null;

    String sql =
        " select sum(qtd_transf) qtd_transf, sum(qtd_sucata) qtd_sucata, sum(hr_tot) hr_tot from joblote\n"
            + " where job = ? and operacao = ? ";

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, job.getJob().trim().replace(".", ""));
    stmt.setInt(2, job.getOperNum());
    rs = stmt.executeQuery();

    if (rs.next()) {

      obj = new ValoresAtualizaJob();
      obj.setQtdTransf(rs.getDouble("qtd_transf"));
      obj.setQtdSucata(rs.getDouble("qtd_sucata"));
      obj.setHoraTotal(rs.getDouble("hr_tot"));
    }

    return obj;
  }
Example #24
0
  public synchronized ItemForSale getItemForSale(int itemId) {
    try {
      PreparedStatement getItemsForSale =
          this.con.prepareStatement(
              "SELECT amount,item_data,posted,price,price_per_item FROM "
                  + this.TBL_ITEMS
                  + " WHERE sold = 0 AND id = ?");
      getItemsForSale.setInt(1, itemId);

      ResultSet result = getItemsForSale.executeQuery();

      if (result.next()) {
        double price = result.getDouble("price");
        double pricePerItem = result.getDouble("price_per_item");
        Date postedDate = result.getTimestamp("posted");

        String sItemData = result.getString("item_data");
        ItemStack is = ItemStackConvertor.fromString(sItemData);

        return new ItemForSale(itemId, is, price, pricePerItem, postedDate);
      }
    } catch (SQLException ex) {
      Logger.getLogger(InventoryManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
  }
  public LeasedVehicle searchClientAndLeasedVehicleByEngineNO(String searchText)
      throws SQLException, ClassNotFoundException {
    Connection connection = DataBaseConnection.getConnection();
    Statement createStatement = connection.createStatement();
    String sql = "";
    ResultSet executeQuery = createStatement.executeQuery(sql);

    LeasedVehicle leasedVehicle = new LeasedVehicle();

    while (executeQuery.next()) {
      leasedVehicle.setLeasingNo(executeQuery.getString("leasingNo"));
      leasedVehicle.setChassisNo(executeQuery.getString("chassisno"));
      leasedVehicle.setColour(executeQuery.getString("colour"));
      leasedVehicle.setCylinderCapacity(executeQuery.getDouble("cylindercapacity"));
      leasedVehicle.setEngineNo(executeQuery.getString("engineno"));
      leasedVehicle.setEstimatedPrice(executeQuery.getDouble("estimatedprice"));
      leasedVehicle.setFuelUsed(executeQuery.getDouble("fuelused"));
      leasedVehicle.setLicensedDate(executeQuery.getString("licenseddate"));
      leasedVehicle.setManufacturedYear(executeQuery.getInt("manufacturedyear"));
      leasedVehicle.setModelAndName(executeQuery.getString("modelandname"));
      leasedVehicle.setRegistrationNo(executeQuery.getString("registrationo"));
      leasedVehicle.setVehicleCategoryId(executeQuery.getString("vehiclecategoryid"));
      leasedVehicle.setWheelBase(executeQuery.getDouble("wheelbase"));
    }

    Client client = leasingDBAccess.searchClientByLeasingNo(leasedVehicle.getLeasingNo());
    leasedVehicle.setClientDetails(client);

    return leasedVehicle;
  }
Example #26
0
  private ArrayList<ItemForSale> getItemsForSale(String queryWhere, int page) {
    ArrayList<ItemForSale> items = new ArrayList<>();

    try {
      PreparedStatement getItemsForSale =
          this.con.prepareStatement(
              "SELECT id,amount,item_data,posted,price,price_per_item FROM "
                  + this.TBL_ITEMS
                  + " WHERE sold = 0 "
                  + queryWhere
                  + " ORDER BY posted DESC,price_per_item LIMIT "
                  + (LonelyShop.SHOP_ITEM_SLOTS * (page - 1))
                  + ","
                  + (LonelyShop.SHOP_ITEM_SLOTS));
      ResultSet result = getItemsForSale.executeQuery();

      while (result.next()) {
        int id = result.getInt("id");
        double price = result.getDouble("price");
        double pricePerItem = result.getDouble("price_per_item");
        Date postedDate = result.getTimestamp("posted");

        String sItemData = result.getString("item_data");
        ItemStack is = ItemStackConvertor.fromString(sItemData);

        items.add(new ItemForSale(id, is, price, pricePerItem, postedDate));
      }
    } catch (SQLException ex) {
      Logger.getLogger(InventoryManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return items;
  }
  public Receipt getReceiptDetails(int receiptId) {

    Receipt receipt = new Receipt();
    try {
      DBConnection receiptSc = (DBConnection) sc.getAttribute("dbConn");
      receiptConn = receiptSc.getDBConnection();
      receiptStmt =
          receiptConn.prepareStatement("SELECT * FROM tbl_student_fees_receipt where receipt_id=?");
      receiptStmt.setInt(1, receiptId);
      receiptRs = receiptStmt.executeQuery();
      receiptRs.next();
      receipt.setReceiptId(receiptRs.getInt("receipt_id"));
      receipt.setStudentId(receiptRs.getInt("student_id"));
      receipt.setSemester(receiptRs.getInt("semester"));
      receipt.setTotalFees(receiptRs.getDouble("total_fees"));
      receipt.setPendingFees(receiptRs.getDouble("fees_pending"));
      receipt.setStatus(receiptRs.getInt("status"));

    } catch (Exception e) {
      System.out.println("Exception in getting receipt details of Receipt controller" + e);
    } finally {
      close();
    }
    return receipt;
  }
 /**
  * @return Numeric meta data information for the channel or <code>null</code>
  * @throws Exception on error
  */
 private Display determineDisplay() throws Exception {
   // Try numeric meta data
   final PreparedStatement statement =
       reader
           .getRDB()
           .getConnection()
           .prepareStatement(reader.getSQL().numeric_meta_sel_by_channel);
   try {
     statement.setInt(1, channel_id);
     final ResultSet result = statement.executeQuery();
     if (result.next()) {
       final NumberFormat format = NumberFormats.format(result.getInt(7)); // prec
       return ValueFactory.newDisplay(
           result.getDouble(1), // lowerDisplayLimit
           result.getDouble(5), // lowerAlarmLimit
           result.getDouble(3), // lowerWarningLimit
           result.getString(8), // units
           format, // numberFormat
           result.getDouble(4), // upperWarningLimit
           result.getDouble(6), // upperAlarmLimit
           result.getDouble(2), // upperDisplayLimit
           result.getDouble(1), // lowerCtrlLimit
           result.getDouble(2)); // upperCtrlLimit
     }
   } finally {
     statement.close();
   }
   // No numeric display meta data
   return null;
 }
Example #29
0
  public static double[][] getRatingDataByKindOfCompanyAndRatingName(int kindOfCompany) {
    double[][] ratingData = null;
    int i = 0;
    try {
      Class.forName(driver);
      conn = DriverManager.getConnection(url, "root", "root");

      String sql = "select * from ratingData where kindOfCompany=" + kindOfCompany;
      Statement st = conn.createStatement();
      ResultSet rs = st.executeQuery(sql);
      if (rs != null && rs.next()) {
        System.out.println("nto null");
        ratingData = new double[20][4];
        rs.beforeFirst();
      }

      while (rs != null && rs.next() && i < 20) {
        ratingData[i][0] = rs.getDouble(4);
        ratingData[i][1] = rs.getDouble(5);
        ratingData[i][2] = rs.getDouble(6);
        ratingData[i][3] = rs.getDouble(7);
        i++;
      }
      rs.close();
      st.close();
      conn.close();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
    return ratingData;
  }
Example #30
0
  protected Envelope getEnvelopeFromResultSet(ResultSet r) throws SQLException {
    Envelope result =
        new Envelope(
            new Coordinate(r.getDouble(2), r.getDouble(3)),
            new Coordinate(r.getDouble(4), r.getDouble(5)));

    return result;
  }