일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- windows
- Kafka
- HTML
- 포인터
- Call-by-reference
- Sort
- 노드
- System
- jsp
- c++
- request
- 투자
- java
- API
- beans
- 윈도우즈
- CLASS
- algorithm
- meta
- query
- 자료구조
- OOP
- C
- JavaScript
- 악성코드
- function
- WebProgramming
- UTF-8
- CSS
- array
- Today
- Total
hahahia
JSP, DB연동을 이용한 회원리스트 구현(계정삭제) 본문
/* list.jsp 일부분(전체 소스는 여기로) */
<table border="1" cellspacing="0">
<tr>
<td>Number</td>
<td>ID</td>
<td>Name</td>
<td>password</td>
<TD>비고 </TD>
</tr>
<%
while(rs.next()) {
%><tr>
<td><%= rs.getInt("idx") /*ⓖ*/%></td>
<td><%=rs.getString(2)%></td>
<td><%= rs.getString(3) /*ⓗ*/%></td>
<td><%=rs.getString("pwd")%></td>
<TD>
<A href="delete-do.jsp?idx=<%=rs.getInt("idx")%>">삭제</A>
<INPUT type="button" value="수정"
onClick="location.href='modify.jsp?idx=<%=rs.getInt("idx")%>'">
</TD>
</tr>
<%
} // end while
%></table>
/* delete-do.jsp */
<%@ page contentType="text/html;charset=utf-8"
import="java.sql.*" %>
<%
request.setCharacterEncoding("utf-8");
String idx = request.getParameter("idx");
try
{
Class.forName("com.mysql.jdbc.Driver");
String DB_URL = "jdbc:mysql://localhost:3306/web01?useUnicode=true&characterEncoding=utf8";
Connection con = DriverManager.getConnection(DB_URL, "admin", "1234");
String sql = "DELETE FROM member WHERE idx=?";
PreparedStatement pstmt = con.prepareStatement(sql); // 쿼리를 이용해 delete 실행!!
pstmt.setInt(1,Integer.parseInt(idx));
pstmt.executeUpdate();
pstmt.close();
con.close();
}
catch(ClassNotFoundException e)
{
out.println(e);
}
catch(SQLException e)
{
out.println(e);
}
response.sendRedirect("list.jsp");
%>
실행결과
삭제라고 써져있는 링크를 눌러보도록 하겠습니다
해당 데이터가 삭제가된걸 볼 수 있네요
MYSQL로 확인해본 TABLE
'Web Programming > JSP' 카테고리의 다른 글
JSP, DB연동을 이용한 회원리스트 구현(회원추가) (0) | 2012.05.25 |
---|---|
JSP, DB연동을 이용한 회원리스트 구현(목록생성) (0) | 2012.05.25 |
Java Beans를 이용한 입출력 (0) | 2012.05.24 |
JSP 문법을 이용한 간단한 피보나치 출력 (0) | 2012.05.05 |
JSP 기초 (0) | 2012.05.05 |