package com.action;


//这里是源包里的p1包中的deleteServlet

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class DeleteServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            String driver="com.mysql.jdbc.Driver";
            String url="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8"
                    + "&serverTimezone=UTC";
            String usr="root";
            String password="123456";
            try{
                Class.forName(driver);
                Connection conn=DriverManager.getConnection(url,usr,password);
                String sqlString="delete from admin where Admin_id=?";
                PreparedStatement pstmt=conn.prepareStatement(sqlString);
                int id =Integer.parseInt(request.getParameter("Admin_id"));
                pstmt.setInt(1, id);
                pstmt.execute();
            }catch(Exception e){
                System.err.println("error:"+e);
            }
            response.sendRedirect("StudentManage.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}
