Пример #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
  // 최근 등록한 게시글이 먼저 나오도록 게시글 목록을 출력한다
  public List<BoardVO> selectAllBoards() {
    System.out.println("selectAllBoards()");
    String sql =
        "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 order by reg_Date desc";
    List<BoardVO> list = new ArrayList<BoardVO>();

    try {
      conn = getConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery(sql);
      while (rs.next()) {
        BoardVO bVo = new BoardVO(); // 게시글 정보를 저장할 BoardVO객체를 생성 함
        bVo.setNum(
            rs.getInt("num")); // rs로 num값을 얻어옴. 얻어온 컬럼 값을 BoardVO객체의 num필드에 저장하기 위해setNum()를 호출 함
        bVo.setMnum(rs.getInt("mnum"));
        bVo.setSubject(rs.getString("subject"));
        bVo.setContent(rs.getString("content"));
        bVo.setReg_date(rs.getDate("reg_date"));
        bVo.setNick(rs.getString("nick"));
        // bVo.setAnswer(rs.getString("answer"));
        System.out.println("bVo : " + bVo.toString());
        list.add(bVo); // List객체에 BoardVO 객체를 추가 함
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      CloseUtil.close(rs);
      CloseUtil.close(stmt);
      CloseUtil.close(conn);
    }
    return list; // qna테이블의 정보가 list객체에 저장되었으므로 이를 리턴 함
  }
Пример #3
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;
  }