예제 #1
0
  public static Towar getTowarById(Integer id) throws Throwable {
    Towar towar = new Towar();
    try {
      Connection pol = BazaKontrolaPolaczenie.getPol();
      Statement st = pol.createStatement();
      ResultSet res = st.executeQuery("SELECT * FROM towar WHERE id=" + id + ";");
      while (res.next()) {
        towar.setId(res.getInt("id"));
        towar.setNazwa(res.getString("nazwa"));
        towar.setCena(res.getDouble("cena"));
      }
    } catch (SQLException ex) {

    }
    return towar;
  }
예제 #2
0
  public List<Towar> getAllTowary() throws Throwable {
    List<Towar> towary = new ArrayList<Towar>();
    try {
      Connection pol = BazaKontrolaPolaczenie.getPol();
      Statement st = pol.createStatement();
      ResultSet res = st.executeQuery("SELECT * FROM towar");
      while (res.next()) {
        Towar towar = new Towar();
        towar.setId(res.getInt("id"));
        towar.setNazwa(res.getString("nazwa"));
        towar.setCena(res.getDouble("cena"));
        towary.add(towar);
      }
    } catch (SQLException ex) {

    }
    return towary;
  }