StartIT

jsp, postgresql 연동으로 db를 tomcat서버에서 접근하기(delete) 본문

Server/centos

jsp, postgresql 연동으로 db를 tomcat서버에서 접근하기(delete)

IT스타터 2020. 6. 29. 22:45
반응형

//delete-do.jsp//

<%@ page contentType="text/html; charset=utf-8" import=" java.sql.*" %>

<%

request.setCharacterEncoding("utf-8");

String num=resquest.getParameter("num");

String url = "jdbc:postgresql://서버주소/디비명";

String usr = "유저명";

String pwd = "password";

try

{

Class.forName("org.postgresql.Driver");

connection con = DriverManager.getConnection(url,usr,pwd);

String sql = "DELETE FROM 테이블명 where num=?";

PreparedStatement pstmt = con.prepareStatement(sql);

pstmt.setInt(1,Integer.parseInt(num));

pstmt.executeUpdate();

pstmt.close();

con.close();

}

catch(ClassNotFountException e)

{

out.println(e);

}

catch(SQLException e)

{

out.println(e);

}

response.sendRedirect("list.jsp");

%>

 

 

참고:

https://hahahia.tistory.com/95?category=446168

 

JSP, DB연동을 이용한 회원리스트 구현(계정삭제)

/* list.jsp 일부분(전체 소스는 여기로) */ Number ID Name password 비고 <% while(rs.next()) { %> <%= rs.getInt("idx") /*ⓖ*/%> <%=rs.getString(2)%> <%= rs.getString(3) /*ⓗ*/%> <%=rs.getString("pwd"..

hahahia.tistory.com

 

반응형
Comments