Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter03 : remove_one 본문

JSP/DB (2)

chapter03 : remove_one

GAWON 2023. 5. 24. 18:55
<%@page import="org.joonzis.db.DBConnect"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
	String id = request.getParameter("id");
	String pw = request.getParameter("pw");


	Connection conn = null;
	PreparedStatement ps = null;
	
	try {
		conn = DBConnect.getConnection();
		String sql ="delete from member where id=? and pw=?"; 
				
		ps = conn.prepareStatement(sql);
		ps.setString(1, id);
		ps.setString(2, pw);
		
		int result = ps.executeUpdate();
		 
		response.sendRedirect("view_all.jsp");
		if(result > 0) {
			System.out.println("데이터 삭제 성공!");
		}else {
			System.out.println("데이터 삭제 실패");
		}
		
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			if (ps != null) {
				ps.close();
			}
			if (conn != null) {
				conn.close();
			}
	
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}
	

%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

'JSP > DB (2)' 카테고리의 다른 글

chapter05 : update  (0) 2023.05.24
chapter04 : update_one  (0) 2023.05.24
chapter02 : insert_one  (0) 2023.05.24
chapter01 : index  (0) 2023.05.24
DBConnect  (0) 2023.05.24