<%@ 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" %>
<%@ page session="true" %>

<% request.setCharacterEncoding("utf-8");%>

<%

String id = request.getParameter("id");
String passwd= request.getParameter("password");
	

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("select id, password from o_member_1 ");
		pstmt.setString(1, id);
		pstmt.setString(2, passwd);
		 
		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 {
//Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String dbpasswd = "";
int x = -1;

try{
	Class.forName("oracle.jdbc.driver.OracleDriver");
	Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","yoon","1234");
	//conn = getConnection();
	            
	pstmt = conn.prepareStatement( "select passwd from o_member_1 where id = ?");
	pstmt.setString(1, id);
	rs= pstmt.executeQuery();

	if(rs.next()){
		dbpasswd= rs.getString("passwd"); {
		if(dbpasswd.equals(passwd))
			x = 1; //인증 성공
		else
			x = 0; //비밀번호 틀림
	}}else
		x = -1;//해당 아이디 없음
				
}catch(Exception ex) {
	ex.printStackTrace();
} 
return x;
}}

%>
<%
 
   // int check= logon.userCheck(id,passwd);

	if(check==1){
		session.setAttribute("id",id);
		response.sendRedirect("sessionMain.jsp");
	}else if(check==0){%>
	<script> 
	  alert("비밀번호가 맞지 않습니다.");
      history.go(-1);
	</script>
<%}else{ %>
	<script>
	  alert("아이디가 맞지 않습니다..");
	  history.go(-1);
	</script>
<%}%>
