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 bdetail="";
		String bpassword="";

		Date bdate= new Date();
		String url="jdbc:oracle:thin:@129.254.75.152:1521:orcl816";
		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>                                          ");
     			out.println("      <center>                                     ");
 	   		bdate = data.date;
 	   		btitle = data.title;
     			bname = data.name;
     			bemail = data.email;
     			bdetail = data.content;
     			bpassword = data.password;

     			out.println("  <h3>글쓰기</h3><hr width=400>                                                    ");
     			out.println("    <form action=BoardUpdate_db method=post>                         ");
     			out.println("        <input type=hidden name=num value="+SQLParam+">");
     			out.println("        <table border=1 >                                                           ");
     			out.println("                <tr><th bgcolor=8f8fbd width=99>이  름 :</th><td>" + bname + "</td>");
     			out.println("          <td width=0></td><th bgcolor=8f8fbd width=85>비밀번호 :</th>                         ");
     			out.println("                    <td width=64><input type=text name=password value="+bpassword+" size = 7 maxlength=5></td></tr>");
     			out.println("                 <tr><th bgcolor=8f8fbd width=99>E-mail :</th>                                            ");
     			out.println("                     <td colspan=4 width=319><input type=text name=email value="+bemail+" size=44 maxlength=20></td></tr>");
     			out.println("                 <tr><th bgcolor=8f8fbd width=99>제 목 :</th>                                             ");
     			out.println("                     <td colspan=4 width=319><input type=text name=title value="+btitle+" size=44 maxlength=40> </td></tr> ");
     			out.println("                 <tr><td colspan=5 width=424><textarea name=content rows=10 cols=60>"+bdetail+"</textarea></td></tr> ");
     			out.println("                 <tr><td colspan=5 align=center width=424><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("비밀번호가 맞지 않습니다. 수정할 권한이 없습니다.");
       			out.println("<meta http-equiv=refresh content=\"2; url=http://localhost:7001/BoardList_db\">");
     	 		System.err.println("SQLException:" + ex.getMessage());
	 	}
   		out.println("   </body> ");
   		out.println("</html> ");
   	}
}

