示例#1
0
  public List<Comment> getCommentByStatusId(String statusId) {
    List<Comment> list = new LinkedList<Comment>();
    Connection conn = null;
    PreparedStatement pStmt = null;
    String sql = "select cid, ctext from comment where sid = ?";
    ResultSet rs = null;
    Comment c = null;

    try {
      conn = DB.getConn();
      pStmt = DB.getpStmt(conn, sql);
      pStmt.setString(1, statusId);
      rs = pStmt.executeQuery();
      while (rs.next()) {
        c = new Comment();
        c.setCid(rs.getString("cid"));
        c.setCtext(rs.getString("ctext"));
        c.setSid(statusId);
        list.add(c);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
      if (pStmt != null) {
        try {
          pStmt.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
    return list;
  }