일반 열세번째날 - WEB APPLICATION

황제낙엽 2003.04.15 10:45 조회 수 : 824 추천:141

sitelink1  
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  
43. JDBC

#######################################
** JSP에서의 예제 **
  // Intialize
  Connection conn = null;
  PreparedStatement pStmt = null;
  ResultSet rset = null;
  
  String ID = "";
  String NAME = "";
  String EMAIL = "";
  String POST = "";
  String DEPT = "";
  String TYPE = "";

  String USERS_ID = request.getParameter("USERS_ID");
  // DB CONNECT
  try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String url = "jdbc:oracle:thin:@mbiz2.mailnara.net:1521:TFTDB";
    conn = DriverManager.getConnection(url,"kebi","kebi");
        StringBuffer buf = new StringBuffer();

        try {
          buf.append("SELECT ");
          buf.append("ID, ");
          buf.append("PWD, ");
          buf.append("NAME, ");
          buf.append("EMAIL, ");
          buf.append("POST, ");
          buf.append("DEPT, ");
          buf.append("TYPE");
          buf.append(" FROM ");
          buf.append("HAKSA_MEMBER");
          buf.append(" WHERE ");
          buf.append("ID='?'");
          pStmt = conn.prepareStatement(buf.toString());
          pStmt.clearParameters();
      pStmt.setString(1, USERS_ID);
          JDFPreparedStatement jdfPstmt = new JDFPreparedStatement(this, buf.toString(), pStmt);
          rset = jdfPstmt.executeQuery();

          while (rset.next()) {
        ID = rset.getString("ID");
        NAME = rset.getString("NAME");
        EMAIL = rset.getString("EMAIL");
        POST = rset.getString("POST");
        DEPT = rset.getString("DEPT");
        TYPE = Integer.toString(rset.getInt("TYPE"));
      }
        }catch (SQLException sqle) {
                
        }finally {
    if(rset != null){
      try { //close시에도 exception이 발생할 수 있기 때문에 각각도 예외처리를 한다.
        rset.close();
      }catch(SQLException e){}
    }
    if(pStmt != null){
      try {
        pStmt.close();
      }catch(SQLException e){}
    }
    if(conn != null){
      try{
        conn.close();
      }catch(SQLException e){}
    }
  }
#######################################

웹서버 설치 방법은 "여기"
그리고 여기서부터의 내용은 자바웹응용편으로 기초 내용이 아니다.
그냥 강의는 들어봤고 예제가 있기 때문에... 정리했다. (아직까지도 헤매고 있다는... -_-;)
참고로 SCJP자격증의 출제범위에는 속하지 않는 내용들이다.

오늘의 예제 :: [14]



44. Servlet (part I)

오늘의 예제 :: [15]



45. Servlet (part II)

오늘의 예제 :: [16]



46. Servlet (part III)

오늘의 예제 :: [17]



47. JSP (part I)

오늘의 예제 :: [18]



48. JSP (part II)

오늘의 예제 :: [19]