|
@@ -0,0 +1,81 @@
|
|
|
|
+package org.lsy.servlet;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.sql.Connection;
|
|
|
|
+import java.sql.DriverManager;
|
|
|
|
+import java.sql.Statement;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletException;
|
|
|
|
+import javax.servlet.http.HttpServlet;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+public class delete extends HttpServlet
|
|
|
|
+{
|
|
|
|
+ // 驱动程序就是之前在classpath中配置的jdbc的驱动程序的jar包中
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 连接地址是由各个数据库生产商单独提供的,所以需要单独记住
|
|
|
|
+ public static final String DBURL = "jdbc:mysql://localhost:3306/kui";
|
|
|
|
+ // 连接数据库的用户名
|
|
|
|
+ public static final String DBUSER = "root";
|
|
|
|
+ // 连接数据库的密码
|
|
|
|
+ public static final String DBPASS = "001011";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
+ throws ServletException, IOException
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
|
+ response.setContentType("text/html;UTF-8");
|
|
|
|
+ PrintWriter out = response.getWriter();
|
|
|
|
+ Connection conn = null; // 表示数据库的连接的对象
|
|
|
|
+ Statement stmt = null; // 表示数据库的更新操作
|
|
|
|
+ //获取表单提交的参数
|
|
|
|
+ String name=request.getParameter("name");
|
|
|
|
+ System.out.println(name);
|
|
|
|
+
|
|
|
|
+ String grent=request.getParameter("grent");
|
|
|
|
+ String result=request.getParameter("result");
|
|
|
|
+ //更新SQL
|
|
|
|
+ String sqlString="delete from student where name='"+name+"' ";
|
|
|
|
+ // 1、使用Class类加载驱动程序
|
|
|
|
+ Class.forName("com.mysql.jdbc.Driver");
|
|
|
|
+ // 2、连接数据库
|
|
|
|
+ conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
|
|
|
|
+ // 3、Statement接口需要通过Connection接口进行实例化操作
|
|
|
|
+ stmt = conn.createStatement();
|
|
|
|
+ int pd=stmt.executeUpdate(sqlString);
|
|
|
|
+ if(pd!=0)
|
|
|
|
+ {
|
|
|
|
+ out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
|
|
|
|
+ out.println("<HTML>");
|
|
|
|
+ out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
|
|
|
|
+ out.println(" <BODY>");
|
|
|
|
+ out.print(" 删除成功<br><a href=MMC_01>查看列表</a> ");
|
|
|
|
+ out.println(" </BODY>");
|
|
|
|
+ out.println("</HTML>");
|
|
|
|
+ }
|
|
|
|
+ out.flush();
|
|
|
|
+ out.close();
|
|
|
|
+ stmt.close();
|
|
|
|
+ conn.close();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
+ throws ServletException, IOException
|
|
|
|
+ {
|
|
|
|
+ doGet(request, response);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|