<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<% request.setCharacterEncoding("utf-8");%>
<%
String id = request.getParameter("ID");
String pw = request.getParameter("pw");
String name = request.getParameter("name");
String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");
String post = request.getParameter("post");
String addr1 = request.getParameter("addr1");
String addr2 = request.getParameter("addr2");
String email1 = request.getParameter("email1");
String email2 = request.getParameter("email2");
String job = request.getParameter("job");
String birth = year + "-" + month + "-" + day;
String addr = addr1 + " " + addr2;
String email = email1 + "@" + email2;
ResultSet rs=null;
String str="";
String sql=null;
try{
	   Class.forName("oracle.jdbc.driver.OracleDriver");
	   Connection  conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","20162505","970401");
	   sql="select * from member_2 where id=? ";
	   PreparedStatement pstmt=conn.prepareStatement(sql);
	   pstmt.setString(1, id);
	   
	   rs=pstmt.executeQuery(); //결과 가져옴
	  
	  if(rs.next()){
	  String dbPass=rs.getString("pw");
	  if(pw.equals(dbPass)){
	  	  pstmt=conn.prepareStatement("update member_2 set pw=?,  name=?, birth=?,post=?,addr=?,email=?,job=? where id=?");
		                                    //UPDATE 테이블명 SET 컬럼명=새로운값 WHERE 업데이트조건 
			pstmt.setString(1,pw);
		  	pstmt.setString(2,name);
		  	pstmt.setString(3,birth);
		  	pstmt.setString(4,post);
		  	pstmt.setString(5,addr);
		  	pstmt.setString(6,email);
		  	pstmt.setString(7,job);
		  	pstmt.setString(8,id);
		  
		  pstmt.executeUpdate();
		  str="정보수정 성공";
		  response.sendRedirect("main2.jsp");
	 }else{
	 str="정보가 일치하지 않습니다.";
	 }}

}catch(Exception e){
e.printStackTrace();
}finally{
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
body
{
    background-color: #5CD1E5;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>정보수정</title>
</head>
<body>
<table border="10" align="center" bordercolor=#008299>
<tr>
<th width = "800" align="center" colspan="3"  bgcolor=#B2EBF4><H1>이런!</H1></th>
</tr>
<tr>
<td width = "600" rowspan="3" align="center"  bgcolor=#B2EBF4>
<%=str %> <p>
다시 시도해주세요.
</tr>
<tr>
<td algin="center" bgcolor=#B2EBF4 >
<button type="button" class="btn btn-default" onclick="location.href='edit.jsp'">이전화면</button></td>
</tr>
</table>
</body>
</html>