• 成绩系统


    package a;
    
    import java.sql.*;
    
    public class A {
    	public Connection database()
    	{
    		Connection connect;
    		try {
            	connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/b?&useSSL=false&serverTimezone=UTC","root","123456");
            	return connect;
    		}catch(Exception e)
    		{
    			e.printStackTrace();  
    		}
    		return null;		
    	}
    	public boolean queryEmpty(String A)
        {
        	boolean flag=false;
            if(A==null||"".equals(A))
            {
                flag=true;
            }
            return flag;
        }
    	public void addS(String A,String B,String C,String D,String E)
    	{
    		try {
    			PreparedStatement preparedStatement=null;
            	Connection connect =database();  	
            	preparedStatement=connect.prepareStatement("insert into achievement (number,name,class,curriculum,achievement) values (?,?,?,?,?)");
                preparedStatement.setString(1,A);
                preparedStatement.setString(2,B);
                preparedStatement.setString(3,C);
                preparedStatement.setString(4,D);
                preparedStatement.setString(5,E);
                preparedStatement.executeUpdate();  
                connect.close();
                preparedStatement.close();           
    		}catch(SQLException e){
    			e.printStackTrace();  
    		}
    	}
    	public void addT(String A,String B)
    	{
    		try {
    			PreparedStatement preparedStatement=null;
            	Connection connect =database();  	
            	preparedStatement=connect.prepareStatement("insert into account (number,password) values (?,?)");
                preparedStatement.setString(1,A);
                preparedStatement.setString(2,B);
                preparedStatement.executeUpdate();  
                connect.close();
                preparedStatement.close();           
    		}catch(SQLException e){
    			e.printStackTrace();  
    		}
    	}
    	public void modify(String A,String B)
    	{
    		try {
    			PreparedStatement preparedStatement=null;
            	Connection connect = database();       	
            	preparedStatement=connect.prepareStatement("Update achievement set achievement=? where number=?");
                preparedStatement.setString(1,A);
                preparedStatement.setString(2,B);
                preparedStatement.executeUpdate();  
                preparedStatement.execute();
                connect.close();   
                preparedStatement.close();
    		}catch(SQLException e){
    			e.printStackTrace();  
    		}
    	}
    	public void deletedata(String A)
        {
    		try {
    			PreparedStatement preparedStatement=null;
    			Connection connect = database();       	
            	preparedStatement=connect.prepareStatement("delete from achievement where number = ?");
                preparedStatement.setString(1,A);
                preparedStatement.executeUpdate();  
                connect.close();
                preparedStatement.close();           
    		}catch(SQLException e){
    			e.printStackTrace();  
    		}
        }
    	public boolean judge(String A)
        {   	
        	boolean flag=true;     
            try {
            	Connection connect = database();
                Statement stmt = connect.createStatement();
                ResultSet rs = stmt.executeQuery("select * from account");
                while(rs.next())
                {
                	if(A.equals(rs.getString("number")))
                    {               		            		
                		flag=false;                  
                    } 
                }            	           	                           
                rs.close();           
                stmt.close();
                connect.close();
            }catch (SQLException e) {
                e.printStackTrace();            
            }
            return  flag;
        }
    	public boolean judgepassword(String A,String B)
        {   	
        	boolean flag=true;     
            try {
            	Connection connect = database();
                Statement stmt = connect.createStatement();
                ResultSet rs = stmt.executeQuery("select * from account");
                while(rs.next())
                {
                	if(A.equals(rs.getString("number"))&&B.equals(rs.getString("password")))
                    {               		            		
                		flag=false;                  
                    } 
                }            	           	                           
                rs.close();           
                stmt.close();
                connect.close();
            }catch (SQLException e) {
                e.printStackTrace();            
            }
            return  flag;
        }
    	public boolean judgeS(String A)
        {   	
        	boolean flag=false;     
            try {
            	Connection connect = database();
                Statement stmt = connect.createStatement();
                ResultSet rs = stmt.executeQuery("select * from achievement");
                while(rs.next())
                {
                	if(A.equals(rs.getString("number")))
                    {               		            		
                		flag=true;                  
                    } 
                }            	           	                           
                rs.close();           
                stmt.close();
                connect.close();
            }catch (SQLException e) {
                e.printStackTrace();            
            }
            return  flag;
        }
    	public boolean numberInt(String A)
    	{
    		boolean flag=true;
    		try {  
    	        double a=Integer.valueOf(A);
    	        if(a>=0) flag=false;
    	        return flag; 
    	    } catch (Exception e) {  
    	        return flag;   
    	    }  
    	}
    	public static void main(String[] args)
    	{
    		A a=new A();
    	}
    }
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>处理</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A" scope="page" />
    <% 
      String number=(String)request.getParameter("number");
      String name=(String)request.getParameter("name");
      String Class=(String)request.getParameter("class");
      String curriculum=(String)request.getParameter("curriculum");
      String achievement=(String)request.getParameter("achievement");
      if(util.queryEmpty(number)||util.queryEmpty(name)||util.queryEmpty(Class)||util.queryEmpty(curriculum)||util.queryEmpty(achievement)){
    	  out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>");
      }else if(util.judgeS(number)){
    	  out.print("<script language ='javaScript'> alert('学号已存在');window.history.back(-1); </script>");
      }else if(util.numberInt(achievement)){
    	  out.print("<script language ='javaScript'> alert('成绩输入不规范');window.history.back(-1); </script>");
      }else{
    	  util.addS(number, name, Class, curriculum, achievement);
    	  out.print("<script language='javaScript'> alert('添加成功');</script>");
    		response.setHeader("refresh", "0;url=teacher.jsp");   
      }
    %>
    </body>
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>增加</title>
    </head>
        <form id="1" action ="addback.jsp" method="get">   
       <p style="text-align:center;color:black;font-family:楷体; font-size:20px">    
                    <br>
                    学号:             
                        <input type="text" name="number"size="15"/>
                    <br><br>                
                    姓名:               
                        <input type="text" name="name"size="16"/>   
                        <br><br>                
                    班级:               
                        <input type="text" name="class"size="16"/>  
                        <br><br>                
                    学科:               
                        <input type="text" name="curriculum"size="16"/>  
                        <br><br>                
                    成绩:               
                        <input type="text" name="achievement"size="16"/>                      
                    <br><br>                  
                    <br><br>            
                        <input type="submit" value="增加"/>
                    <br><br> 
                        <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" />     
        </p>
        </form>  
    
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>删除</title>
    </head>
        <form id="1" action ="delSback.jsp" method="get">   
       <p style="text-align:center;color:black;font-family:楷体; font-size:20px">    
                    <br>
                    账号:             
                        <input type="text" name="number"size="15"/>
                    <br><br>                                
                    <br><br>            
                        <input type="submit" value="删除"/>
                    <br><br>            
                        <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" />      
        </p>
        </form>  
    
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>处理</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A" scope="page" />
    <% 
      String number=(String)request.getParameter("number");
      if(util.queryEmpty(number)){
    	  out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>");
      }else if(!util.judgeS(number)){
    	  out.print("<script language ='javaScript'> alert('学号不存在');window.history.back(-1); </script>");
      }else{
    	  util.deletedata(number);
    	  out.print("<script language='javaScript'> alert('删除成功');</script>");
    		response.setHeader("refresh", "0;url=teacher.jsp");   
      }
    %>
    </body>
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>登录系统</title>
    </head>
        <form id="1" action ="signIn.jsp" method="get">   
       <p style="text-align:center;color:black;font-family:楷体; font-size:20px">    
                    <br>
                    账号:             
                        <input type="text" name="number"size="15"/>
                    <br><br>                
                    密码:               
                        <input type="password" name="password"size="16"/>                       
                    <br><br>                  
                    <br><br>            
                        <input type="submit" value="登录"/>
                        <input type="button" value="注册" onclick="location.href='register.jsp'" />     
        </p>
        </form>  
    
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>修改</title>
    </head>
        <form id="1" action ="modifyback.jsp" method="get">   
       <p style="text-align:center;color:black;font-family:楷体; font-size:20px">    
                    <br>
                    账号:             
                        <input type="text" name="number"size="15"/>
                    <br><br>
                    成绩:             
                        <input type="text" name="achievement"size="15"/>
                    <br><br>                                                                
                    <br><br>            
                        <input type="submit" value="修改"/>
                    <br><br>            
                        <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" />      
        </p>
        </form>  
    
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>处理</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A" scope="page" />
    <% 
      String number=(String)request.getParameter("number");
      String achievement=(String)request.getParameter("achievement");
      if(util.queryEmpty(number)||util.queryEmpty(achievement)){
    	  out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>");
      }else if(!util.judgeS(number)){
    	  out.print("<script language ='javaScript'> alert('学号不存在');window.history.back(-1); </script>");
      }else if(util.numberInt(achievement)){
    	  out.print("<script language ='javaScript'> alert('成绩输入不规范');window.history.back(-1); </script>");
      }else{
    	  util.modify(achievement, number);
    	  out.print("<script language='javaScript'> alert('修改成功');</script>");
    		response.setHeader("refresh", "0;url=teacher.jsp");   
      }
    %>
    </body>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>登录系统</title>
    </head>
        <form id="1" action ="queryback.jsp" method="get">   
       <p style="text-align:center;color:black;font-family:楷体; font-size:20px">    
                    <br>
                    学号或姓名:             
                        <input type="text" name="A"size="15"/>                                
                    <br><br>                  
                    <br><br>            
                        <input type="submit" value="查询"/>
                    <br><br>            
                        <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" />  
         
        </p>
        </form>  
    
    </html>
    

      

    <%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
    <html>
    <head>
    <title>查询</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A"/>
    <table border="1"style="text-align:center">
    <caption>成绩</caption>
    <tr>
    <td align="center" width=3%>学号</td>
    <td align="center" width=3%>姓名</td>
    <td align="center" width=3%>班级</td>
    <td align="center" width=3%>学科</td>
    <td align="center" width=3%>成绩</td>
    </tr>
    <%
    String A=(String)request.getParameter("A");
    try{
    	Connection connect = util.database();
    	PreparedStatement preparedStatement=null; 
    	ResultSet rs = null;
    	preparedStatement=connect.prepareStatement("select * from achievement where number like ? or name like ?");
    	preparedStatement.setString(1,"%"+A+"%");
        preparedStatement.setString(2,"%"+A+"%");
        rs=preparedStatement.executeQuery();
        while(rs.next()){
    		   %>
    		   <tr>
    		   <td width=3% align="center"><%=rs.getObject(1) %></td>
    		   <td width=3% align="center"><%=rs.getObject(2) %></td>	
    		   <td width=3% align="center"><%=rs.getObject(3) %></td>
    		   <td width=3% align="center"><%=rs.getObject(4) %></td>	
    		   <td width=3% align="center"><%=rs.getObject(5) %></td>	   
    		   </tr>
    		   <%
        }
        rs.close();
        preparedStatement.close();
        connect.close();
    }catch (SQLException e) {
        e.printStackTrace();            
    }
    %>
    </table>
    <p style="text-align:center;color:black;font-family:宋体; font-size:20px">
                <br>             
                <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> 
        </p>  
    </body>
    </html>
    

      

    <%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
    <html>
    <head>
    <title>排序</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A"/>
    <table border="1"style="text-align:center">
    <caption>成绩</caption>
    <tr>
    <td align="center" width=3%>学号</td>
    <td align="center" width=3%>姓名</td>
    <td align="center" width=3%>班级</td>
    <td align="center" width=3%>学科</td>
    <td align="center" width=3%>成绩</td>
    </tr>
    <%
    try{
    	Connection connect = util.database();
        Statement stmt = connect.createStatement();
        ResultSet rs = stmt.executeQuery("select *from achievement order by achievement desc");
        while(rs.next()){	
        	%>
        	   <tr>
    		   <td width=3% align="center"><%=rs.getObject(1) %></td>
    		   <td width=3% align="center"><%=rs.getObject(2) %></td>	
    		   <td width=3% align="center"><%=rs.getObject(3) %></td>
    		   <td width=3% align="center"><%=rs.getObject(4) %></td>	
    		   <td width=3% align="center"><%=rs.getObject(5) %></td>	   
    		   </tr>
    		<%
        }
        rs.close();           
        stmt.close();
        connect.close();
    }catch (SQLException e) {
        e.printStackTrace();            
    }
    %>
    </table>
    <p style="text-align:center;color:black;font-family:宋体; font-size:20px">
                <br>             
                <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" /> 
        </p>  
    </body>
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>注册系统</title>
    </head>
        <form id="1" action ="register-back.jsp" method="get">   
       <p style="text-align:center;color:black;font-family:楷体; font-size:20px">    
                    <br>
                    账号:             
                        <input type="text" name="number"size="15"/>
                    <br><br>                
                    密码:               
                        <input type="password" name="password"size="16"/>                       
                    <br><br>                  
                    <br><br>            
                        <input type="submit" value="注册"/>
                    <br><br>
                        <input type="button" value="返回上一页" onclick="javascript:history.back(-1)" />  
        </p>
        </form>  
    
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>注册处理</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A" scope="page" />
    <% 
      String number=(String)request.getParameter("number");
      String password=(String)request.getParameter("password");
      if(util.queryEmpty(number)||util.queryEmpty(password)){
    	  out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>");
      }else if(!util.judge(number)){
    	  out.print("<script language ='javaScript'> alert('账号已存在');window.history.back(-1); </script>");
      }else{
    	  util.addT(number, password);
    	  out.print("<script language='javaScript'> alert('注册成功');</script>");
    		response.setHeader("refresh", "0;url=index.jsp");   
      }
    %>
    </body>
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>登录处理</title>
    </head>
    <body>
    <jsp:useBean id="util" class="a.A" scope="page" />
    <% 
      String number=(String)request.getParameter("number");
      String password=(String)request.getParameter("password");
      if(util.queryEmpty(number)||util.queryEmpty(password)){
    	  out.print("<script language ='javaScript'> alert('输入不能为空');window.history.back(-1); </script>");
      }else if(util.judge(number)){
    	  out.print("<script language ='javaScript'> alert('未查询到改账号');window.history.back(-1); </script>");
      }else if(util.judgepassword(number, password)){
    	  out.print("<script language ='javaScript'> alert('密码错误');window.history.back(-1); </script>");
      }else{
    	  out.print("<script language='javaScript'> alert('登录成功');</script>");
    		response.setHeader("refresh", "0;url=teacher.jsp");   
      }
    %>
    </body>
    </html>
    

      

    <%@ page contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>登录系统</title>
    </head>
    	<p style="text-align:center;color:black;font-family:宋体,serif; font-size:20px">
    	<br><br>
    	<input type="button" value="增加学生" onclick="location.href='addS.jsp'" /> 
    	<br><br>
    	<input type="button" value="删除学生" onclick="location.href='delS.jsp'" />
    	<br><br>
    	<input type="button" value="修改成绩" onclick="location.href='modify.jsp'" />
    	<br><br>
    	<input type="button" value="查询成绩" onclick="location.href='query.jsp'" />
    	<br><br>
    	<input type="button" value="成绩排名" onclick="location.href='ranking.jsp'" />
    	<br><br>
        </p>	
    </html>
    

      

  • 相关阅读:
    idea 严重: Error configuring application listener of class org.springframework.web.context.Context 后面省略
    idea 新建 maven项目遇到的一些问题
    常用的DOS命令
    我对速汇金业务的理解
    和同事下班路上讨论心得(服务器部署的几点问题)
    5/6月学习工作总结(压力越大,意志越坚定)
    苏州银行对公久悬户
    苏州银行对公定存通项目
    苏州银行对公存款业务模块维护
    [转载]一个人的失败,99%失败于“脾气”
  • 原文地址:https://www.cnblogs.com/da48/p/14229054.html
Copyright © 2020-2023  润新知