note

JSP ORACLE DELETE 레코드 삭제 본문

Oracle/기본

JSP ORACLE DELETE 레코드 삭제

투한 2012. 2. 9. 09:50













<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>레코드 삭제 예제</title>
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");

	String id = request.getParameter("id");
	String passwd = request.getParameter("passwd");
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	try{
		String jdbcUrl ="jdbc:oracle:thin:@localhost:1521:orcl";
		String dbId="hr";
		String dbPass="hr";
		
		//JDBC수행 1단계 : jdbc Driver 로드
		Class.forName("oracle.jdbc.driver.OracleDriver");
		//JDBC수행 2단계 : Connection 객체 생성
		conn=DriverManager.getConnection(jdbcUrl,dbId,dbPass);
		
		String sql="select id, passwd from member1 where id= ?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1,id);
		rs=pstmt.executeQuery();
		
		if(rs.next()){
			String rId=rs.getString("id");
			String rPasswd=rs.getString("passwd");
			if(id.equals(rId) && passwd.equals(rPasswd)){
				sql="delete from member1 where id= ? ";
				pstmt=conn.prepareStatement(sql);
				pstmt.setString(1,id);
				pstmt.executeUpdate();
				%>
	member1 테이블의 레코드를 삭제했습니다.
	<%
			}else{
				out.println("패스워드가 틀렸습니다.");
			}
		}else{
			out.println("아이디가 틀렸습니다.");
		}
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		if(rs != null)
			try{rs.close();}catch(SQLException sqle){}
		if(pstmt != null)
			try{pstmt.close();}catch(SQLException sqle){}
		if(conn != null)
			try{conn.close();}catch(SQLException sqle){}
	}
%>
</body>
</html>