Exemplo n.º 1
0
  public static void deletePost(Long post_ID) throws SQLException {
    Post post = null;

    String deletePostStr =
        String.format("DELETE from %s where postid = ?", Post.dquote(POST), post_ID);

    Connection conn = null;
    PreparedStatement deleteP = null;

    if (post_ID != null) {
      try {
        conn = DB.getConnection();
        deleteP = conn.prepareStatement(deletePostStr);
        ResultSet rs = deleteP.executeQuery();

        if (rs.next()) {
          Logger.debug("Failed to delete the Post.");
        }
        deleteP.close();
        conn.close();
      } catch (SQLException e) {
        Logger.debug("Failed while trying to delete the post.");
      }
    } else {
      Logger.debug("Post id is null.");
    }
  }
Exemplo n.º 2
0
  /**
   * FindById Searches the database for a Group object by the object id.
   *
   * @param connection The jdbc connection
   * @param id The id to select by
   */
  public static Post FindByID(Long post_ID) throws SQLException {
    Post post = null;
    PreparedStatement findPostId = null;
    Connection conn = null;

    String sql = String.format("SELECT * from %s where postid = ?", Post.dquote(POST), post_ID);

    if (post_ID != null) {
      try {
        conn = DB.getConnection();
        findPostId = conn.prepareStatement(sql);
        findPostId.setLong(1, post_ID);

        ResultSet rs = findPostId.executeQuery();

        if (rs.next()) {
          post =
              new Post(
                  rs.getString(Post.CONTENT),
                  rs.getString(Post.TYPE),
                  rs.getTimestamp(Post.TIMESTAMP),
                  rs.getLong(Post.USER_ID),
                  rs.getLong(Post.WALL_ID),
                  rs.getLong(Post.POST_ID));
        }

        findPostId.close();
        conn.close();
        return post;
      } catch (SQLException e) {
        Logger.debug("Error retrieving post.", e);
      }
    }
    return post;
  }