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

import javax.servlet.*;
import javax.servlet.http.*;
/**----------------------------------------------------------------------------
 * BoardView_db
 *
 * author  batmanii
 * version 1.0 (2000/07/22)
 */
///////////////////////////////////////////////////////////////////////////////
public class BoardChange_db extends HttpServlet
{
    	String filename;
    	String    page;

    	public void doPost(HttpServletRequest req, HttpServletResponse res)	throws IOException
    	{
    		ChangeItem changeItem = new ChangeItem();

        		res.setContentType("text/html;charset=euc-kr");
        		// 이렇게 charset을 지정해야지 한글이 깨지지 않는다는군요.
       		PrintWriter  out = res.getWriter();

		//	int bnum = -1;
		String bname="";
		String btitle="";
		String bemail="";
		String bcontent="";
		String bpassword="";

		Date bdate= new Date();
		String url="jdbc:oracle:thin:@localhost:1521:etri";
		Connection con;
		Statement stmt;

		String SQLParam=req.getParameter("num");
  		bpassword = req.getParameter("password");
		page = req.getParameter("page");

		if(page==null) page="0";

		try
		{
	  		changeItem.loadDriver();
		}
		catch(ClassNotFoundException e)
		{
	  		System.err.print("ClassNotFoundException:");
	  		System.err.println(e.getMessage());
		}
		catch(Exception e)
		{
	   		System.err.println(e);
		}

		try
		{	   // DB Connecte
			BoardData data = changeItem.change(SQLParam, bpassword);

	   		out.println("<html>                                             ");
     			out.println("   <body  background=/images/back.gif>                                          ");
     			out.println("      <center>                                     ");
 	   		bdate = data.date;
 	   		btitle = data.title;
     			bname = data.name==null? "":data.name;
     			bemail = data.email==null? "":data.email;
     			bcontent = data.content==null? "":data.content;
     			bpassword = data.password==null? "":data.password;

     			out.println("  <br><img src=\"/images/boardEditTitle.gif\" width=\"273\" height=\"34\"> <br><br>                                                 ");
     			out.println("    <form action=BoardUpdate_db method=post>                         ");
     			out.println("        <input type=hidden name=num value="+SQLParam+">");
     			out.println("        <table border=0 cellspacing=1 cellpadding=5 width=600 style=\"font-size:12px\"  bgcolor=#995F0F>");
     			out.println("                <tr><th bgcolor=#D3BB9A width=\"100\">이  름 :</th><td bgcolor=#FFFFFF>" + bname + "</td></td>");
     			out.println("          <tr><th bgcolor=#D3BB9A>비밀번호 :</th>                         ");
     			out.println("                    <td width=64 bgcolor=#FFFFFF><input type=text name=password value="+bpassword+" size = 7 maxlength=5></td></tr>");
     			out.println("                 <tr><th bgcolor=#D3BB9A>E-mail :</th>                                            ");
     			out.println("                     <td bgcolor=#FFFFFF><input type=text name=email value=\""+bemail+"\"  size=44 maxlength=20></td></tr>");
     			out.println("                 <tr><th bgcolor=#D3BB9A>제 목 :</th>                                             ");
     			out.println("                     <td bgcolor=#FFFFFF><input type=text name=title value="+btitle+" size=44 maxlength=40> </td></tr> ");
     			out.println("                 <tr><th bgcolor=#D3BB9A>내 용 :</th>  <td  bgcolor=#FFFFFF><textarea name=content rows=10 cols=60>"+bcontent+"</textarea></td></tr> ");
     			out.println("                 <tr  bgcolor=#F3EBE2><td colspan=2 align=center ><input type=submit value=등록>     ");
     			out.println("                                               <input type=reset value=다시쓰기></td></tr>  ");
     			out.println("           </table>  ");
     			out.println("      </form> ");
     			out.println("  </center> ");
	 	}
	 	catch(SQLException ex)
	 	{
       			out.println("<script>alert('비밀번호가 맞지 않습니다. 수정할 권한이 없습니다.');");
       			out.println("self.location='BoardList_db'</script>");
     	 		System.err.println("SQLException:" + ex.getMessage());
	 	}
   		out.println("   </body> ");
   		out.println("</html> ");
   	}
}

