Exemplo n.º 1
0
  public static void update(Seller seller) {

    try {
      PreparedStatement ps =
          c.prepareStatement(
              "UPDATE Sellers SET first_name=?, second_name=?, password=? where id=?");

      ps.setString(1, seller.getName());
      ps.setString(2, seller.getSurname());
      ps.setString(3, seller.getPassword());
      ps.setInt(4, seller.getId());
      ps.executeUpdate();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
 public static Seller get(int id) {
   Seller seller = new Seller();
   String query = "Select * from Sellers where id=" + id;
   try {
     ResultSet result = statement.executeQuery(query);
     if (result.next()) {
       seller.setId(result.getInt(1));
       seller.setName(result.getString(2));
       seller.setSurname(result.getString(3));
       seller.setPassword(result.getString(4));
     }
   } catch (SQLException e) {
     return null;
   }
   return seller;
 }
Exemplo n.º 3
0
  public static List<Seller> getAll() {
    List<Seller> list = new ArrayList<Seller>();
    String query = "Select * from Sellers";
    try {

      ResultSet result = statement.executeQuery(query);
      while (result.next()) {
        Seller seller = new Seller();
        seller.setId(result.getInt(1));
        seller.setName(result.getString(2));
        seller.setSurname(result.getString(3));
        seller.setPassword(result.getString(4));
        list.add(seller);
      }
    } catch (SQLException e) {
    }
    return list;
  }
Exemplo n.º 4
0
  public static Seller save(Seller seller) {
    try {
      String query = "Select max(id) from Sellers";
      ResultSet result;
      result = statement.executeQuery(query);

      if (result.next()) seller.setId(result.getInt(1) + 1);

      PreparedStatement ps =
          c.prepareStatement(
              "Insert into Sellers (id,first_name, second_name, password) values(?,?,?,?)");
      ps.setInt(1, seller.getId());
      ps.setString(2, seller.getName());
      ps.setString(3, seller.getSurname());
      ps.setString(4, seller.getPassword());
      ps.executeUpdate();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return seller;
  }