JSP学生信息管理系统设计(3)

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>条件删除提交页面</title> </head> <body> 请选择删除记录条件<<hr size="3"> <form action="studelete2.jsp" method="post"> 姓名:<input type="text"><br><br> 性别:男<input type="radio" value="男"> 女<input type="radio" value="女"><br><br> 年龄范围:<br><p> 最小:<input type="text"><br> 最大:<input type="text"> </p> <input type="submit" value="提交"> <input type="reset" value="取消"> </form> </body> </html>

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%> <html> <head> <title>条件删除处理页面</title> </head> <body> <% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String user="sa"; String password="123456"; String url="jdbc:sqlserver://localhost:1433;DatabaseName=p"; Connection conn=DriverManager.getConnection(url,user,password); request.setCharacterEncoding("UTF-8"); String name=request.getParameter("name"); String sex=request.getParameter("sex"); String ag1=request.getParameter("a1"); String ag2=request.getParameter("a2"); int a3,a4; String sql="delete from Student where Sname=? and Ssex=? and Sage>=? and Sage<=?"; PreparedStatement pstmt=conn.prepareStatement(sql); if(!name.equals("")) pstmt.setString(1,name); if(sex!=null) pstmt.setString(2,sex); if(!ag1.equals("")){a3=Integer.parseInt(ag1); pstmt.setInt(3,a3);} if(!ag2.equals("")){a4=Integer.parseInt(ag2); pstmt.setInt(4,a4);} int n=pstmt.executeUpdate(); if(n==1){%>数据删除成功<br><%} else{%>数据删除失败!<br><%} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} %> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjgdy.html