171201 getAllBoard() - RYUDONGJIN/Memo_wiki GitHub Wiki

//모든 게시글을 리턴해주는 메소드 작성
public ArrayList<BoardBean> getAllBoard(int start, int end){
	//리턴할 객체 선언
	ArrayList<BoardBean> al = new ArrayList<>();
	getCon();
	try {
		//쿼리 준비 
		String sql = "SELECT * FROM (SELECT A.*, Rownum Rnum FROM (SELECT * FROM Board ORDER BY ref desc, re_step asc)A) WHERE Rnum >= ? and Rnum <= ?";
		//쿼리를 실행할 객체
		pstmt = con.prepareStatement(sql);
		pstmt.setInt(1, start);
		pstmt.setInt(2, end);
		//쿼리 실행 후 결과 저장
		rs = pstmt.executeQuery();
		//데이터 개수가 몇개인지 모르기에 반복문을 이용하여 데이터를 추출
		while(rs.next()) {
			//데이터를 패키징(BoardBean클래스를 이용)
			BoardBean bean = new BoardBean();
			bean.setNum(rs.getInt(1));
			bean.setWriter(rs.getString(2));
			bean.setEmail(rs.getString(3));
			bean.setSubject(rs.getString(4));
			bean.setPassword(rs.getString(5));
			bean.setReg_date(rs.getDate(6).toString());
			bean.setRef(rs.getInt(7));
			bean.setRe_step(rs.getInt(8));
			bean.setRe_level(rs.getInt(9));
			bean.setReadcount(rs.getInt(10));
			bean.setContent(rs.getString(11));
			//패키징한 데이터를 리스트에 저장
			al.add(bean);
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			if(rs != null) rs.close();
			if(pstmt != null) pstmt.close();
			if(con != null) con.close();
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}
	return al;
}
⚠️ **GitHub.com Fallback** ⚠️