NoticeConsole

private int count;
	
	public NoticeConsole() {
		service = new NoticeService();
		page= 1;
		count = 0;
	}
	

	public void printNoticeList() throws ClassNotFoundException, SQLException {
		List<Notice> list = service.getList(page);
		count = service.getCount();
		
		System.out.println("─────────s───────────");
		System.out.printf("<공지사항> 총 %d 게시글\n",count); 
		System.out.println("────────────────────");

count 변수를 줘서 getCount 를 생성했다.

NoticeService


	// Scalar ( 단일값을 얻는 함수)
	public int getCount() throws SQLException, ClassNotFoundException {
		int count = 0;
		String sql = "SELECT COUNT(ID) COUNT FROM NOTICE";
		
		Class.forName(driver);
		Connection con = DriverManager.getConnection(url,uid,pwd);
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery(sql);
		
		if(rs.next())
			count = rs.getInt("COUNT");
			
		rs.close();
		st.close();
		con.close();
		
		return count;
	}

별칭을 줘서 간단하게 총게시글을 구해봤다.

게시글개수

댓글남기기