示例#1
0
  public PageTO page(int curPage) {
    PageTO to = new PageTO();
    int totalCount = totalCount();

    ArrayList<BoardVO> list = new ArrayList<BoardVO>();
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = getConnection();
      // String query = "select * from qna";
      String query =
          "select q.num num, q.mnum mnum, q.subject subject, q.reg_Date reg_date,"
              + " q.content content, q.anwser anwser, m.nick nick from MEMBER m, QNA q where "
              + "m.mnum=q.mnum";
      pstmt =
          conn.prepareStatement(
              query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

      rs = pstmt.executeQuery();

      int perpage = to.getPerPage(); // 5

      int skip = (curPage - 1) * perpage;
      if (skip > 0) {
        rs.absolute(skip);
      }
      for (int i = 0; i < perpage && rs.next(); i++) {

        int num = rs.getInt("num");
        int mnum = rs.getInt("mnum");
        String Subject = rs.getString("subject");
        Date Reg_date = rs.getDate("Reg_date");
        String content = rs.getString("content");
        String answer = rs.getString("anwser");
        String nick = rs.getString("nick");

        BoardVO data = new BoardVO();
        data.setNum(num);
        data.setMnum(mnum);
        data.setSubject(Subject);
        data.setReg_date(Reg_date);
        data.setContent(content);
        data.setAnwser(answer);
        data.setNick(nick);
        list.add(data);
      }
      to.setList(list); // ArrayList 저장
      to.setTotalCount(totalCount); // 전체 레코드 개수ˆ˜
      to.setCurPage(curPage); // 현재 페이지€
    } catch (Exception e) {
      e.printStackTrace();

    } finally {
      CloseUtil.close(rs);
      CloseUtil.close(pstmt);
      CloseUtil.close(conn);
    } // end finally
    return to;
  } // end page
示例#2
0
  // 게시판 글 상세 내용 보기 :글번호로 찾아온다. : 실패 null,
  // qna 테이블에서 게시글번호로 해당 게시글을 찾아 게시글 정보를 BoardVO 객체로 얻어준다
  public BoardVO selectOneBoardByNum(String num) {
    StringBuffer sb = new StringBuffer();
    sb.append("select q.num num, q.mnum mnum, q.subject subject, q.reg_date reg_date, ");
    sb.append("q.content content, q.anwser anwser, m.nick nick from member m, qna q where ");
    sb.append("m.mnum=q.mnum and q.num=?");

    BoardVO bVo = null;

    try {
      conn = getConnection();
      pstmt = conn.prepareStatement(sb.toString());
      pstmt.setString(1, num);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        bVo = new BoardVO();
        bVo.setNum(rs.getInt("num"));
        bVo.setMnum(rs.getInt("mnum"));
        bVo.setSubject(rs.getString("subject"));
        bVo.setContent(rs.getString("content"));
        bVo.setReg_date(rs.getDate("reg_date"));
        bVo.setAnwser(rs.getString("anwser"));
        bVo.setNick(rs.getString("nick"));

        System.out.println(rs.getString("nick"));
        System.out.println(bVo);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      CloseUtil.close(rs);
      CloseUtil.close(pstmt);
      CloseUtil.close(conn);
    }
    return bVo;
  }
示例#3
0
 public void selectReply(String num) {
   String sql = "select anwser from qna where num = ?";
   BoardVO bVo = null;
   try {
     conn = getConnection();
     pstmt = conn.prepareStatement(sql);
     pstmt.setString(1, num);
     rs = pstmt.executeQuery();
     bVo = new BoardVO();
     if (rs.next()) {
       bVo.setAnwser(rs.getString("anwser"));
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     CloseUtil.close(pstmt);
     CloseUtil.close(conn);
   }
 }