示例#1
0
  public boolean loadComment() throws IOException, SQLException {
    if (pageNo * countPerPage >= totalCount) {
      return false;
    }

    Connection conn = null;
    PreparedStatement pStmt = null;
    String sql = "select ctext from comment limit ?, ?";
    ResultSet rs = null;
    int i = 0;

    conn = DB.getConn();
    pStmt = DB.getpStmt(conn, sql);
    pStmt.setInt(1, (pageNo * countPerPage));
    pStmt.setInt(2, countPerPage);
    rs = pStmt.executeQuery();
    while (rs.next()) {
      comm[i] = rs.getString(1);
      i++;
    }
    pageNo++;
    rs.close();
    pStmt.close();
    conn.close();
    return true;
  }
示例#2
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;
  }
示例#3
0
 private void loadTotalNum() {
   Connection conn = null;
   Statement stmt = null;
   String sql = "select count(*) from comment";
   ResultSet rs = null;
   conn = DB.getConn();
   stmt = DB.getStmt(conn);
   try {
     rs = stmt.executeQuery(sql);
     while (rs.next()) {
       totalCount = rs.getInt(1);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     if (rs != null) {
       try {
         rs.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
     if (stmt != null) {
       try {
         stmt.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
     if (conn != null) {
       try {
         conn.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }