欢迎来到天天文库
浏览记录
ID:40557618
大小:38.50 KB
页数:7页
时间:2019-08-04
《JSP页面实现批量删除数据》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、JSP页面实现批量删除数据首次:FindServlet.Java-->bookList.jsp删除:bookList.jsp-->DelServlet.java-->FindServlet..java实现批量删除,首先获取要删除的行的idStringID[]=request.getParameterValues("delid");checkbox的name为delid,值为id值,选择选择框,就会获取到id值。SQL语句采用批处理命令:StringID[]=request.getParameterValues(
2、"delid");//获取要删除的图书编号if(ID.length>0){for(inti=0;i3、ckAll(elementsA,elementsB){for(i=0;i4、tringname;//图书名称privatedoubleprice;//定价privateintbookCount;//数量privateStringauthor;//作者..DelServlet.java//packagecom.mingrisoft;importjava.io.IOException;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjavax.serv5、let.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/***Servlet实现类UpdateServlet*/@WebServlet("/DelServlet")//配置Servletpub6、licclassDelServletextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;publicDelServlet(){super();}/***处理POST请求*/protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{try{Class.forName("com.mysql7、.jdbc.Driver");//加载数据库驱动,注册到驱动管理器Stringurl="jdbc:mysql://localhost:3306/db_book";//数据库连接字符串Stringusername="root";//数据库用户名Stringpassword="root";//数据库密码//创建Connection连接Connectionconn=DriverManager.getConnection(url,username,password);Stringsql="DELETEFROMtb_bo8、okWHEREid=?";//更新SQL语句PreparedStatementps=conn.prepareStatement(sql);//获取PreparedStatementStringID[]=request.getParameterValues("delid");//获取要删除的图书编号if(ID.length>0){for(inti=0;i
3、ckAll(elementsA,elementsB){for(i=0;i4、tringname;//图书名称privatedoubleprice;//定价privateintbookCount;//数量privateStringauthor;//作者..DelServlet.java//packagecom.mingrisoft;importjava.io.IOException;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjavax.serv5、let.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/***Servlet实现类UpdateServlet*/@WebServlet("/DelServlet")//配置Servletpub6、licclassDelServletextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;publicDelServlet(){super();}/***处理POST请求*/protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{try{Class.forName("com.mysql7、.jdbc.Driver");//加载数据库驱动,注册到驱动管理器Stringurl="jdbc:mysql://localhost:3306/db_book";//数据库连接字符串Stringusername="root";//数据库用户名Stringpassword="root";//数据库密码//创建Connection连接Connectionconn=DriverManager.getConnection(url,username,password);Stringsql="DELETEFROMtb_bo8、okWHEREid=?";//更新SQL语句PreparedStatementps=conn.prepareStatement(sql);//获取PreparedStatementStringID[]=request.getParameterValues("delid");//获取要删除的图书编号if(ID.length>0){for(inti=0;i
4、tringname;//图书名称privatedoubleprice;//定价privateintbookCount;//数量privateStringauthor;//作者..DelServlet.java//packagecom.mingrisoft;importjava.io.IOException;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjavax.serv
5、let.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/***Servlet实现类UpdateServlet*/@WebServlet("/DelServlet")//配置Servletpub
6、licclassDelServletextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;publicDelServlet(){super();}/***处理POST请求*/protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{try{Class.forName("com.mysql
7、.jdbc.Driver");//加载数据库驱动,注册到驱动管理器Stringurl="jdbc:mysql://localhost:3306/db_book";//数据库连接字符串Stringusername="root";//数据库用户名Stringpassword="root";//数据库密码//创建Connection连接Connectionconn=DriverManager.getConnection(url,username,password);Stringsql="DELETEFROMtb_bo
8、okWHEREid=?";//更新SQL语句PreparedStatementps=conn.prepareStatement(sql);//获取PreparedStatementStringID[]=request.getParameterValues("delid");//获取要删除的图书编号if(ID.length>0){for(inti=0;i
此文档下载收益归作者所有