code083.java
package pack02;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//DeleteServlet�࣬��code080.jsp������ã�ɾ�����ݿ�����
@WebServlet(name="code083",urlPatterns = "/page04/pack02.code083")
public class code083 extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
int id = Integer.valueOf(request.getParameter("id"));
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String pwd = "mysql123";
Connection conn = DriverManager.getConnection(url,user,pwd);
String sql = "delete from tb_books where id=?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setInt(1, id);
stmt.executeUpdate();
stmt.close();
conn.close();
} catch (Exception e)
{
e.printStackTrace();
}
response.sendRedirect("pack02.code079"); //ɾ����Ϻ���Findservlet�࣬��ʾ���ݿ�����
}
}