5. ±Û ¾²±â¸¦ À§ÇÑ Å¬·¡½º Á¤ÀÇ(Write.java)

µ¥ÀÌÅ͸¦ ÀÔ·ÂÇÒ ¶§ °¡Àå Æí¸®ÇÑ ¹æ¹ýÀº ¿ª½Ã ½ºÅ©¸³Æ²¸´À¸·Î ÀÛ¼ºÇÏ´Â °ÍÀÔ´Ï´Ù.

±»ÀÌ µ¥ÀÌÅÍ ÀÔ·Á󸮸¦ À§ÇÑ ºóÁ ÀÛ¼ºÇÒ ÇÊ¿äµµ ¾øÀ¸´Ï±î¿ä.. ÇÏÁö¸¸ Áö±Ý±îÁö ºóÁî·Î ó¸®ÇßÀ¸´Ï±î À̰͵µ °Á ºóÁî·Î ó¸®ÇØ º¸°Ú½À´Ï´Ù. ¼Ò½ºÀÇ ¾çÀº Á» ¸¹¾ÆÁö°ÚÁö¸¸ ºóÁî¿¡ ´ëÇÑ ÀÌÇصµ È®½ÇÈ÷ ÇÒ ¼ö ÀÖÀ» »Ó´õ·¯ À߸¸ ¼³°èµÈ´Ù¸é µÎ°íµÎ°í ÀÌ¿ëÇÒ ¼ö ÀÖÀ» °Í °°½À´Ï´Ù.

±Û¾²±â ÀÔ·Â Æû À̳ª ÀÎÁõó¸® ºÎºÐÀº »ç½Ç ¿©±â¼­ Áß¿äÇÑ ºÎºÐÀÌ ¾Æ´Õ´Ï´Ù.

½ÇÁ¦·Î ºóÁî°¡ ¾î¶»°Ô µ¥ÀÌÅ͸¦ ó¸®ÇÏ´ÂÁö¿Í ¶Ç º¸¿©Áֱ⠷ÎÁ÷(JSP ÆäÀÌÁö)¿¡¼­´Â ¾î¶»°Ô ±¸ÇöÀ» ÇÏ´À³Ä ÀÔ´Ï´Ù.

°Ô½ÃÆÇ ÀÛ¼º ·ÎÁ÷Àº ÀÌ¹Ì ¸¹Àº ¹æ¹ýµéÀÌ °ø°³µÇ¾î ÀÖ°í À¥ÇÁ·Î±×·¡¹ÖÀ» ÇϽŴٸé Á¦ÀÏ ¸ÕÀú Á¢ÇϽô ºÎºÐÀ̶ó »ý°¢µË´Ï´Ù.

±×·¡¼­ ÀÌ ºÎºÐ¿¡¼­´Â ÀÔ·Â Æû À̳ª ÀÎÁõó¸® ºÎºÐÀº °ú°¨È÷ »ý·«Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.

°ü½É ÀÖÀ¸½Å ºÎºÐÀº ¼Ò½º¸¦ Âü°íÇϽñ⠹ٶø´Ï´Ù(»ç½Ç ¿Ïº®ÇÏÁö´Â ¾Ê½À´Ï´Ù.^^;;).

 

±Û¾²±â¸¦ ó¸®Çϱâ À§ÇÑ ºóÁîµµ ¸®½ºÆ® Ãâ·Â ºóÁî¿Í ¸¶Âú°¡Áö·Î °¢ µ¥ÀÌÅ͸¦ ¼³Á¤(setProperty)ÇÏ°í ºóÁî³»ÀÇ µ¥ÀÌÅÍ Ã³¸® ¸Þ¼­µå¸¦ È£ÃâÇÏ¸é µË´Ï´Ù.

SetProperty ¸Þ¼­µå´Â ÇÊ¿äÇÑ ¿ä¼ÒµéÀ» ÀÏÁ¤ÇÑ Çü½Ä setXXX(Object obj) Çü½ÄÀ¸·Î ÀÛ¼ºÇÏ½Ã¸é µÇ°í µ¥ÀÌÅÍ Ã³¸® ¸Þ¼­µå´Â ÀÌ·¸°Ô ¼ÂÆÃ(?)µÈ ÀڷḦ µ¥ÀÌÅÍ º£À̽º¿¡ Ãß°¡Çϰųª »èÁ¦ÇÏ´Â µîÀÇ ÀÏ·ÃÀÇ ÇàÀ§(?)¸¦ ±¸ÇöÇÏ¸é µË´Ï´Ù.

 

cmd.jsp

<%@ page contentType="text/html; charset=euc-kr" %>

<jsp:useBean id="ModifyDB" class="board.Write"/>

<%

String PAGE = request.getParameter("PAGE");

String key = request.getParameter("KEY");

String field = request.getParameter("FIELD");

String cmd = request.getParameter("CMD");

String no = request.getParameter("NO");

String name = request.getParameter("NAME");

String email = request.getParameter("EMAIL");

String subject = request.getParameter("SUBJECT");

String passwd = request.getParameter("PASSWD");

String content = request.getParameter("CONTENT");

%>

<jsp:setProperty name="ModifyDB" property="cmd" value="<%=cmd%>"/>

<jsp:setProperty name="ModifyDB" property="no" value="<%=no%>"/>

<jsp:setProperty name="ModifyDB" property="name" value="<%=name%>"/>

<jsp:setProperty name="ModifyDB" property="email" value="<%=email%>"/>

<jsp:setProperty name="ModifyDB" property="subject" value="<%=subject%>"/>

<jsp:setProperty name="ModifyDB" property="passwd" value="<%=passwd%>"/>

<jsp:setProperty name="ModifyDB" property="content" value="<%=content%>"/>

<%

ModifyDB.modifyData();

response.sendRedirect("list.jsp?PAGE=" + PAGE + "&KEY=" + key + "&FIELD=" + field);

%>

 

ÀÏ´Ü setProperty·Î µ¥ÀÌÅ͸¦ ¼ÂÆÃÈÄ modifyData() ¸¦ È£ÃâÇϹǷνá ÀÛ¾÷ÀÌ ¸¶¹«¸®µÇµµ·Ï ÇÏ¿´½À´Ï´Ù.

modifyData() ´Â ¼ÂÆÃµÈ Ä¿¸Çµå¿¡ µû¶ó ºÐ±â¸¦ Çϴµ¥..

cmd.jsp ¿¡¼­´Â ¼öÁ¤°ú ÀÔ·Â(»õ·Î¿î±Û) ¸¸ÀÌ Ã³¸®µË´Ï´Ù. ³ª¸ÓÁö »èÁ¦´Â write.jsp¿¡¼­ ¾ÏÈ£¸¦ È®ÀÎÈÄ Write.java ÀÇ deleteData(int no) ¸¦ È£ÃâÇϹǷνá ÀÌ·ç¾î Áý´Ï´Ù.

 

¿¹·Î ±Û ÀԷ ó¸® ¸Þ¼­µå¸¦ »ìÆ캸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

 

write.java

public void addData() throws SQLException{

    int group_id = getMaxGroup();

    Connection con = null;

    PreparedStatement pstmt = null;

    String query;

 

    query = "INSERT INTO BOARD_T " +          

"(NAME,EMAIL,SUBJECT,CONTENT,¡±  +

¡°REGI_DATE,CNT,GROUP_ID,DEPTH,GROUP_ORDER,PASSWD)" +

                " VALUES (?,?,?,?,sysdate(),0,?,0,0,?)";

    try{

      con = getDBConnection();

 

      pstmt = con.prepareStatement(query);

      pstmt.setString(1,name);

      pstmt.setString(2,email);

      pstmt.setString(3,subject);

      pstmt.setString(4,content);

      pstmt.setInt(5,group_id);

      pstmt.setString(6,passwd);

      pstmt.execute();

      con.commit();

    }catch(SQLException e){

      e.getMessage();

    }finally{

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

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

    }

  }

 

´«¿©°Ü º¸½Ç ºÎºÐÀ̶ó¸é preparedStatement ¸¦ »ç¿ëÇß´Ù´Â Á¡°ú ÀԷµǴ °¢ Çʵ尪À»

preparedStatement ÀÇ setString À̳ª setInt ÀÇ ¸Þ¼­µå¸¦ »ç¿ëÇØ ÀÔ·Âó¸®ÇÑ ºÎºÐÀÔ´Ï´Ù.

ÀÌ·¸°Ô ó¸®ÇÏ¸é ´Üµû¿ÈÇ¥¸¦ Ưº°È÷ º¯È¯ÇØÁÖÁö ¾Ê¾Æµµ µÈ´Ù´Â Á¡ÀÔ´Ï´Ù.

°Ô´Ù°¡ ¹Ýº¹µÇ´Â ÀÛ¾÷Àº preparedStatement¸¦ ¾²´Â °ÍÀÌ ¼º´É»ó À¯¸®ÇÕ´Ï´Ù.

 

³ª¸ÓÁö ÀÛ¾÷À» À§ÇØ ÇÊ¿äÇÑ ¸Þ¼­µå´Â ¼Ò½º¸¦ Âü°í ÇϽñ⠹ٶø´Ï´Ù.

 

ÀÌ·Î½á °Ô½ÃÆÇ ¸¸µé±â¸¦ À§ÇÑ »çÇ×µéÀ» ¼Ò½º¿Í ÇÔ²² »ìÆì º¸¾Ò½À´Ï´Ù.

´Ù¸¥ ½ºÅ©¸³Æ® ¾ð¾î¿Í´Â ¸¹Àº Á¡µéÀÌ ´Ù¸¦°ÍÀÔ´Ï´Ù. ƯÈ÷ ºóÁ ÀÌ¿ëÇØ °¢ ±â´Éº°·Î ÄÄÆ÷³ÍƮȭ ½ÃŲÁ¡À̳ª ű׶óÀ̺귯¸®¸¦ ¾´ ºÎºÐÀº ¿©Å¸ÀÇ ¾ð¾î¿¡¼­´Â ã¾Æº¸±â Èûµç °­·ÂÇÑ ±â´ÉÀ̶ó ÇÒ ¼ö ÀÖ½À´Ï´Ù.

¹°·Ð ´ÜÁ¡µµ ¾øÁö¾Ê¾Æ ÀÖ½À´Ï´Ù.

ƯÈ÷ ¿À¹öÇìµå°¡ ¸¹ÀÌ °É¸®´Â µ¥ÀÌÅͺ£À̽º ¿¬°áºÎºÐÀÌ ÃÖÀûÈ­ µÇ¾î ÀÖÁö ¾ÊÀº Á¡À̳ª

Áö³ªÄ¡°Ô ¸¹Àº ¸Þ¼­µå·Î ±¸ºÐÇÑÁ¡µîÀÌ ±×·¯ÇÕ´Ï´Ù.

¸Þ¼­µå(DB ÄÁ³Ø¼Ç)°¡ ¸¹¾Æ Áö±â ¶§¹®¿¡ ¿À¹öÇìµåµµ ¸¹ÀÌ °É¸®°Ô µË´Ï´Ù.

¿å½ÉÀ» ³»ÀÚ¸é ÀÌ·¯ÇÑ ºÎºÐÀº Ä¿³Ø¼Ç Ç®¸µÀ» »ç¿ëÇÏ°í ´õ ³ª¾Æ°¡ EJB·ÎÀÇ ÀüÇâÀ» °í·ÁÇÏ´Â °ÍÀÔ´Ï´Ù.

 

±×·³ À̸¸ ÁÙÀÌ°Ú½À´Ï´Ù.