import java.io.*;
import java.sql.*;
import java.util.Date;

public class ReadBoardList
{
    	int totalListNum;
    	int totalPage;
    	int pageListNum;


	public ReadBoardList()
	{
	}

	public void loadDriver() throws ClassNotFoundException, Exception
	{
  		Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
	}


	public BoardData[] readList() throws SQLException
	{
    		String url="jdbc:oracle:thin:@129.254.75.152:1521:orcl816";
    		Connection con;
    		Statement stmt;
    		String query = "select BNUM, BDATE, BNAME, BEMAIL, BTITLE from board order by bnum ";
    		String CountQuery = "select count(*) as rc from board ";

	   		// DB Connecte
          	con = DriverManager.getConnection(url, "scott", "tiger");
        		stmt = con.createStatement();

	   	// Record Count
        	  	ResultSet rs = stmt.executeQuery(CountQuery);
        	  	//레코드 처음으로 이동
	         rs.next();
            	int RecordCount = rs.getInt("rc");
            	//총 레코드수를 RecordCount,totalListNum에 입력
            	totalListNum = RecordCount;

            	// 게시물 수 체크
        	  	if(totalListNum == 0)
        	          		return null;
 	         // 전체 몇페이지인지를 구하고, 한 화면에 10개의 게시물 표시
	         totalPage = totalListNum/HTMLLib.LINENUM+1;

            	// pageListNum : 현재 페이지에 표시될 게시물 숫자
	         if(totalListNum!=0 && pageListNum==0)
	                		pageListNum=HTMLLib.LINENUM;
        		// 게시물수만큼의 BoardData변수 db생성
            	BoardData[] bd = new BoardData[totalListNum];
 	       	// db에 리스트화일을 열어 저장
       	    	int i = 0;
         	rs = stmt.executeQuery(query);
        		// Date객체하나 만들고..

        	  	while(rs.next())
        	  	{
               		bd[i] = new BoardData(rs.getInt("BNUM"), rs.getDate("BDATE"),rs.getString("BTITLE"),  rs.getString("BNAME"), rs.getString("BEMAIL"), null, null);
	    	   	i++;
         	  }

	          stmt.close();
            	con.close();

	 	return bd;
	}


	public int getTotalListNum()
	{
		return totalListNum;
	}

	public int getTotalPage()
	{
		return totalPage;
	}

	public int getPageListNum()
	{
		return pageListNum;
	}
}
