public List<Notice> getList(int page, String field, String query) throws ClassNotFoundException, SQLException {
		
		int start = 1+(page-1)*10;					//1, 11, 21, 31 ...
		int end = 10*page; //10 , 20 , 30, 40 .... 
		
		String sql = "SELECT * FROM NOTICE_VIEW WHERE "+field+" LIKE ? AND NUM BETWEEN ? AND ?";
			
		Class.forName(driver);
		Connection con = DriverManager.getConnection(url,uid,pwd);
		PreparedStatement st = con.prepareStatement(sql);
		st.setString(1, "%"+query+"%");
		st.setInt(2, start);
		st.setInt(3, end);
		ResultSet rs = st.executeQuery();
		
		List<Notice> list = new ArrayList<Notice>();
		
		
		while(rs.next()) {
			int id = rs.getInt("ID");
			String title = rs.getString("title");
			String wirterid = rs.getString("WRITER_ID");
			Date regDate=rs.getDate("REGDATE");
			String content = rs.getString("CONTENT");
			int hit =rs.getInt("HIT");
			String files = rs.getString("FILES");
			
			Notice notice = new Notice(
					id,
					title,
					wirterid,
					regDate,
					content,
					hit,
					files
					);
			
			list.add(notice);
			
		}
		rs.close();
		st.close();
		con.close();
		return list;
	}
	

String field, String query 추가함. SQL문 수정

public void printNoticeList() throws ClassNotFoundException, SQLException {
		List<Notice> list = service.getList(page, searchFiled, searchWord );
		int count = service.getCount();

searchFiled, searchWord 추가

검색2

여기서 다음시간에는 총게시글과 페이지수를 수정할것이다.

출처 : 뉴렉쌤 유투브

댓글남기기