コード例 #1
0
ファイル: DAO.java プロジェクト: Aganom/MMSEProject
  private EventRequestBean getFromResultSet(ResultSet resultSet) throws SQLException {

    EventRequestBean eventRequest;
    String id = resultSet.getString(1);
    eventRequest = new EventRequestBean(id);
    String name = resultSet.getString(2);
    eventRequest.setName(name);
    int clientId = resultSet.getInt(3);
    eventRequest.setClientId(clientId);
    String type = resultSet.getString(4);
    eventRequest.setType(type);
    Date from = resultSet.getDate(5);
    eventRequest.setFrom(from);
    Date to = resultSet.getDate(6);
    eventRequest.setTo(to);
    String budget = resultSet.getString(7);
    eventRequest.setBudget(budget);
    String status = resultSet.getString(8);
    eventRequest.setStatus(status);
    Map<String, String> preferences = eventRequest.getPreferences();
    preferences.put("details_photo_video", resultSet.getNString(9));
    preferences.put("details_music", resultSet.getNString(10));
    preferences.put("details_poster", resultSet.getNString(11));
    preferences.put("details_decoration", resultSet.getNString(12));
    preferences.put("details_network", resultSet.getNString(13));
    preferences.put("details_food_beverages", resultSet.getNString(14));
    preferences.put("details_waiter", resultSet.getNString(15));
    preferences.put("feedback_budget", resultSet.getNString(16));
    return eventRequest;
  }
コード例 #2
0
ファイル: DAO.java プロジェクト: Aganom/MMSEProject
  /**
   * Add event request to persistent store
   *
   * @param toAdd event to add
   * @return id of added event, or -1 if unsuccessful
   */
  public int addEventRequest(EventRequestBean toAdd) {
    String insertStatement =
        "insert into eventrequests "
            + "(clientid, type, name, fromdate, todate, budget,"
            + " status, details_photo_video, details_music,"
            + " details_poster, details_decoration, details_network,"
            + " details_food_beverages, details_waiter, feedback_budget)"
            + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
    try {
      PreparedStatement statement =
          connection.prepareStatement(insertStatement, Statement.RETURN_GENERATED_KEYS);
      statement.setInt(1, toAdd.getClientId());
      statement.setNString(2, toAdd.getType());
      statement.setNString(3, toAdd.getName());
      statement.setDate(4, new java.sql.Date(toAdd.getFrom().getTime()));
      statement.setDate(5, new java.sql.Date(toAdd.getTo().getTime()));
      statement.setNString(6, toAdd.getBudget());
      statement.setNString(7, toAdd.getStatus());
      Map<String, String> preferences = toAdd.getPreferences();
      statement.setNString(8, preferences.get("details_photo_video"));
      statement.setNString(9, preferences.get("details_music"));
      statement.setNString(10, preferences.get("details_poster"));
      statement.setNString(11, preferences.get("details_decoration"));
      statement.setNString(12, preferences.get("details_network"));
      statement.setNString(13, preferences.get("details_food_beverages"));
      statement.setNString(14, preferences.get("details_waiter"));
      statement.setNString(15, preferences.get("feedback_budget"));

      statement.executeUpdate();
      ResultSet rs = statement.getGeneratedKeys();
      if (!rs.next()) {
        return -1;
      }
      return (int) rs.getLong(1);

    } catch (SQLException e) {
      e.printStackTrace();
    }
    return -1;
  }