이 포스트에서는 jsp로 데이터를 삭제하여 mysql의 테이블에 있는 데이터를 삭제합니다.



 * delete_form.jsp


 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>Delete_form Page</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<br> 삭제할 아이디를 입력하세요. <br>
<form name="form1" action="delete_DB.jsp" method="post">
<p> ID: <input type="text" name="id"><br><br>
<input type="submit" name="formbutton1" value="보내기">&nbsp;</p>
</form>
<p>&nbsp;</p>

</body>
</html>


좋은 글이면 손가락 눌러 주세요. 힘이 됩니다 ^^ 

로그인이 필요 없습니다.





* delete_DB.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>Delete Database Page</title>
</head>
<body>
<%@ page import = "java.sql.*, java.util.*" %>
<%
String id = request.getParameter("id");
String password = request.getParameter("password");

Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
PreparedStatement pstmt = null;


try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "admin");
pstmt = conn.prepareStatement("delete from jsp where id = ? ");
pstmt.setString(1, id);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {

if(pstmt != null)
try {
pstmt.close();
} catch (Exception e) {}
if(conn != null)
try {
conn.close();
} catch (Exception e) {}
}
%>
입력하신 ID, Password 정보가 삭제되었습니다.
</body>
</html>



* delete_from.jsp 실행 화면





* 삭제할 아이디를 입력 후 보내기 버튼 클릭시 화면
  ID: errortest 의 데이터를 삭제하겠습니다.






* 삭제된 정보를 확인하기 위해 read_DB.jsp 실행 화면
  




posted by 쪼재