<NoticeList.java>

 

* DB Connection ó ޼( www.webbdox.co.kr )

 

package tag;

import java.sql.*;

import java.io.*;

import java.util.*;

import javax.servlet.jsp.PageContext;

 

public class NoticeList{

    private final static String JDBC_DRIVER_NAME = "org.gjt.mm.mysql.Driver";

    private final static String DATABASE_URL = "jdbc:mysql://xxx.xxx.x.xx:3306/testdb";

    private final static String DATABASE_USER = "userid";

    private final static String DATABASE_PASSWORD = "password";            

   

   

             

    /***************************************************

     *

     *                 database Driver εѴ.

     *

     ***************************************************/

              

    public void loadJDBCDriver(){

      try {

          Class.forName(JDBC_DRIVER_NAME);

      } catch (Exception e) {}

    }

   /***************************************************

    *

    *                   DB Connection ü ´.

    *

    ***************************************************/

   private Connection getDBConnection() throws SQLException {

return DriverManager.getConnection(DATABASE_URL, DATABASE_USER,        

DATABASE_PASSWORD);

}

}

 

DB Connection κ ó Ͽϴ.

Ŭ Connection ʿ  ִٴ Դϴ. ̷ Ϸ ϰ ̸ о óϴ ϹԴϴ. ϴ κ̰ Properties Ŭ ̿ϴ ִµ κ Tip & Tech ÷ ϰڽϴ.

 

<NoticeList.java>

 

* (¡ ó)

 

 

public class NoticeList{

   

   

    private int page;         // setProperty Ǵ ()

    private int list_cnt;      // setProperty Ǵ

    private int total;          // ü

    private String key;      // ˻

    private String field;     // ˻ʵ

    private int no;                    // б index No

 

   

   

   

    /***************************************************

     *

     *                 DB Field ´.

     *

     ***************************************************/

              

    public Vector getList() throws SQLException{

 

      Connection con = null;

      Statement stmt = null;

      ResultSet rs = null;

 

      Vector v = new Vector();

      String query ;

      int recNum; // ڵ                                                    

      recNum = total;

                         

      try{                                      

         con = getDBConnection();

         stmt = con.createStatement();                                         

         query = "SELECT NO,SUBJECT,CONTENT,REGI_DATE,CNT FROM NOTICE_T " + getWhere() +          

         " ORDER BY REGI_DATE DESC";

                         

         rs = stmt.executeQuery(query);

                         

         for(int i=0;i<(page-1)*list_cnt;i++){

                  recNum--;

                  rs.next();

         }

                                      

         for(int i=0;i<list_cnt;i++){                                                                                         

                  NoticeRec nr = new NoticeRec();

                  if(!rs.next()){break;}

                  nr.num = recNum;

                  nr.no = rs.getInt("NO");

                  nr.subject = rs.getString("SUBJECT");

                  nr.content = rs.getString("CONTENT");

                  nr.regi_date = rs.getString("REGI_DATE");

                  nr.cnt = rs.getInt("CNT");

                  v.addElement(nr);                                     // NoticeRec ü Vector ִ´      

                  recNum--;

         }                         

      }catch(SQLException e){

                   throw new SQLException(e.getMessage());

      }finally{

                  if (rs != null) rs.close();

                  if (stmt != null) stmt.close();

                  if (con != null) con.close();

      }

         return v;

}

   

   

}

 

Ϳ  ͵ ʽϴ.

ϴ ŭ Ϳ 㵵 մϴ.

 

<ü >

public class NoticeList{

/***************************************************

 *

 *                 ü ´.

 *

 ***************************************************/

public int getTotal() throws SQLException{

       Connection con = null;

       Statement stmt = null;

       ResultSet rs = null;

      

       String query;                

      

       try{

         con = getDBConnection();                                                           

         stmt = con.createStatement();  

         query = "SELECT COUNT(*) AS TOTAL FROM NOTICE_T " + getWhere() + " ORDER BY

                     REGI_DATE DESC";

         rs = stmt.executeQuery(query);

                                                          

         while(rs.next()){                                                   

            total = rs.getInt("TOTAL");

         }

       }catch(SQLException e){

          e.getMessage();

       }finally{

          if(rs != null) rs.close();

          if(stmt != null) stmt.close();

          if(con != null) con.close();

       }

       return total;

}     

  }

 



Ʈ
- ± ̺귯 Ʃ丮 (www.orionsever.com)
- www.webdox.co.kr
- jsp.boolpae.com
- Web Development with JavaServerPages ()
- ڹ α׷ (Ѻ ̵)
- Ʈ JSP (Ѻ ̵)