コード例 #1
0
ファイル: PostMapper.java プロジェクト: urobo/FubMe
  public static final void unlikes(User user, Post post) {
    Connection connection = null;
    PreparedStatement stmt = null;
    String sql = " DELETE FROM luser_likes_post where luser_id = ? and post_id = ?";
    try {
      connection = DBConnection.getConnection();
      stmt = connection.prepareStatement(sql);
      stmt.setString(1, user.getId());
      stmt.setInt(2, post.getId());
      stmt.executeUpdate();
    } catch (SQLException ex) {
      Logger.getLogger(PostMapper.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      if (stmt != null)
        try {
          stmt.close();
        } catch (SQLException e1) {
          e1.printStackTrace();
        }

      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #2
0
ファイル: PostMapper.java プロジェクト: urobo/FubMe
  public static final void createPost(Post post) {
    Connection connection = null;
    PreparedStatement stmt = null;
    String sql =
        "INSERT INTO post ("
            + Post.LUSER_ID
            + ","
            + Post.LINK
            + " ,"
            + Post.BODY
            + ","
            + Post.MIME
            + ") VALUES ( ?, ?, ?, ? ) RETURNING id";
    try {
      connection = DBConnection.getConnection();
      stmt = connection.prepareStatement(sql);
      stmt.setString(1, post.getUser_id());
      stmt.setString(2, (post.getLink() != null) ? post.getLink().toString() : "null");
      stmt.setString(3, post.getBody());
      stmt.setString(4, post.getMime());
      ResultSet id = stmt.executeQuery();
      id.next();
      Logger.getLogger(PostMapper.class.getName())
          .log(Level.SEVERE, "post number " + id.getInt("id"));
      if (post.getTags() != null) {
        post.setId(id.getInt("id"));
        Tagger.tagAs(post);
      }
      stmt.close();
    } catch (SQLException ex) {
      Logger.getLogger(PostMapper.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      if (stmt != null)
        try {
          stmt.close();
        } catch (SQLException e1) {
          e1.printStackTrace();
        }

      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }