<%@ 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 passwd= request.getParameter("password");
   String name = request.getParameter("name");   
   String hobby = request.getParameter("hobby");
   String address= request.getParameter("address");
   String school = request.getParameter("school");    
      
   String str="";
   
   try{
	 
	   Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","yoon","1234");
		PreparedStatement pstmt=conn.prepareStatement("insert into o_member_1(id,password,name,hobby,address,school) values(?,?,?,?,?,?)");
		pstmt.setString(1, id);
		pstmt.setString(2, passwd);
		pstmt.setString(3, name);
		pstmt.setString(4, hobby);
		pstmt.setString(5, address);
		pstmt.setString(6, school);
		pstmt.executeUpdate();
		pstmt.close();
		conn.close();  
	 	 
 	 str=  "님 가입을 축하드립니다.";
 	}catch(Exception e){ 
 		e.printStackTrace();
 		str="o_member_1 테이블에 새로운 레코드를 추가에 실패했습니다";
	
 	}
   
 
 
 //  public int userCheck(String id, String passwd)throws Exception{
	public int userCheck(String id, String passwd) throws Exception{
		
	}
	   ResultSet rs=null;
	   String dbpasswd="";
	   int x=-1;
	   String id;
	  try{
		  Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","yoon","1234");
			PreparedStatement pstmt=conn.prepareStatement("select password from o_member_1 where id=?");
			 
			  
			pstmt.setString(1,id);
			rs=pstmt.executeQuery();
			
			if(rs.next()){
				dbpasswd=rs.getString("password");
				if(dbpassword.equals(password))
					x=1;//인증성공
					else
						x=0;//비밀번호틀림
			}else
				x=-1;//해당아이디 없음
			
			 
			 
	  }catch(Exception ex) {
		   ex.printStackTrace();
		   
	   }finally{
		   if(rs!=null)
			   try{rs.close();}catch(SQLException ex){}
		  if(pstmt!=null)
			   try{pstmt.close();}catch(SQLException ex){}
		  if(conn!= null)
			   try{conn.close();}catch(SQLException ex){}
	  }
	   return x;
   }
 
 %>
<html>
<head>
<title>레코드 추가</title>
</head>
<body>
  <%=name %>
  <%=str %>  <p>
  
 <A href="http://localhost:8080/jsp_Test/o_member_test_2/inputTest.jsp">로그인   click here!! </A><p>
  <A href="http://localhost:8080/jsp_Test/o_member_test_2/list.jsp">전제 회원 보기  click here!! </A>
  
</body>
</html>