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