綜合學生信息管理系統(JSP+JDBC)

原創html


經過JSP+JDBC製做一個簡單的操做數據庫中表信息的系統。java

整體界面以下,一共有5個功能塊。sql

功能一:列出所有學生數據庫

功能二:按條件查詢學生session

 

功能三:新添加學生框架

功能四:按條件刪除學生jsp

功能五:按條件修改學生sqlserver

 

JSP頁面介紹(鏈接的數據名稱爲DB OF CWM,操做的表爲Student):post

綜合數據庫系統總頁面.jsp —— 設計整體頁面的框架ui

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫系統總頁面</title>
    </head>
    <frameset rows="80,*">
        <frame src="綜合數據庫頁面_up.jsp" scrolling="no">
        <frameset cols="140,*">
            <frame src="綜合數據庫頁面_down_left.jsp" scrolling="no">
            <frame src="綜合數據庫_down_right.jsp" name="right" scrolling="no">
        </frameset>
    </frameset>
</html>

綜合數據庫頁面_up.jsp —— 設計整體頁面的上方(即圖中的學生數據庫管理系統)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <h1 align="center">學生數據庫管理系統</h1>
    </head>
</html>

綜合數據庫頁面_down_left.jsp —— 設計整體頁面的下方的左邊(即顯示五個超連接的功能塊)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>菜單頁面</title>
    </head>
    <body>
        <br><br><br><br><br><br>
        <p><a href="綜合數據庫_down_left_列出所有學生.jsp" target="right">列出所有學生</a>
        <p><a href="綜合數據庫_down_left_按條件查詢學生.jsp" target="right">按條件查詢學生</a>
        <p><a href="綜合數據庫_down_left_新添加學生.jsp" target="right">新添加學生</a>
        <p><a href="綜合數據庫_down_left_按條件刪除學生.jsp" target="right">按條件刪除學生</a>
        <p><a href="綜合數據庫_down_left_按條件修改學生.jsp" target="right">按條件修改學生</a>
    </body>
</html>

綜合數據庫_down_right.jsp —— 設計整體頁面的下方的右邊(即圖中的綜合數據庫管理)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫_down_right</title>
    </head>
    <body>
        <h2 align="center">綜合數據庫管理</h2>
    </body>
</html>

綜合數據庫_down_left_列出所有學生.jsp —— (鏈接數據庫顯示錶Student的全部學生信息,數據庫鏈接密碼本身修改)

<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>列出所有學生</title>
    </head>
    <body>
        <%
            String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            Class.forName(driverName);
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=DB OF CWM";
            String userName="sa";
            String pwd="*******";
            Connection conn=DriverManager.getConnection(dbURL,userName,pwd);
            String sql="select *from student";
            PreparedStatement stmp=conn.prepareStatement(sql);
            ResultSet rs=stmp.executeQuery();
            while(rs.next()){ %>
                <table cellpadding="1">
                    <tr>
                        <td><%=rs.getString("Sno") %></td>
                        <td><%=rs.getString("Sname") %></td>
                        <td><%=rs.getString("Ssex") %></td>
                        <td><%=rs.getString("Sage") %></td>
                        <td><%=rs.getString("Sdept") %></td>
                    </tr>
                </table>
                <%
            }%>
            <%
                if(rs!=null){
                    rs.close();
                }
                if(stmp!=null){
                    stmp.close();
                }
                if(conn!=null){
                    conn.close();
                }
            %>
    </body>
</html>

綜合數據庫_down_left_按條件查詢學生.jsp

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>按條件查詢學生</title>
    </head>
    <body>
        請輸入學生的如下信息進行查詢:<br><br>
        <form action="綜合數據庫_down_left_按條件查詢學生_查詢結果.jsp" method="post">
            學號: <input type="text" name="Sno"><br><br>
            姓名: <input type="text" name="Sname"><br><br>
            &nbsp;&nbsp;&nbsp;<input type="submit" value="肯定">&nbsp;&nbsp;&nbsp;
            <input type="reset" value="取消">
        </form>
    </body>
</html>

綜合數據庫_down_left_按條件查詢學生_查詢結果.jsp

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫_down_left_按條件查詢學生_查詢結果</title>
    </head>
    <body>
        <h2>查詢結果以下:</h2><br><br>
        <%
            request.setCharacterEncoding("UTF-8");
            String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            Class.forName(driverName);
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=DB OF CWM";
            String userName="sa";
            String pwd="******";
            Connection conn=DriverManager.getConnection(dbURL,userName,pwd);
            String snonum=request.getParameter("Sno");
            String Ssname=request.getParameter("Sname");
            String sql="select * from Student where Sno=? and Sname=?";
            PreparedStatement stmp=conn.prepareStatement(sql);
            stmp.setString(1, snonum);
            stmp.setString(2, Ssname);
            ResultSet rs=stmp.executeQuery();
            while(rs.next()){%>
                <table cellpadding="1">
                    <tr>
                        <td><%=rs.getString("Sno") %></td>
                        <td><%=rs.getString("Sname") %></td>
                        <td><%=rs.getString("Ssex") %></td>
                        <td><%=rs.getString("Sage") %></td>
                        <td><%=rs.getString("Sdept") %></td>
                    </tr>
                </table>
            <%
            }
            if(rs!=null){
                rs.close();
            }
            if(stmp!=null){
                stmp.close();
            }
            if(conn!=null){
                conn.close();
            }
            %>
    </body>
</html>

綜合數據庫_down_left_新添加學生.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>新添加學生</title>
    </head>
    <body>
        <b>請填入如下信息(信息不能爲空):</b><br><br>
        <form action="綜合數據庫_down_left_新添加學生_插入.jsp" method="post">
            <table>
                <tr>學號: <input type="text" name="Sno"></tr><br><br>
                <tr>姓名: <input type="text" name="Sname"></tr><br><br>
                <tr>性別: 男 <input type="radio" name="Ssex" value="男"><input type="radio" name="Ssex" value="女"></tr><br><br>
                <tr>年齡: <input type="text" name="Sage"></tr><br><br>
                <tr>學院: <input type="text" name="Sdept"></tr><br><br>
                <tr colspan="3">&nbsp;&nbsp;&nbsp;<input type="submit" value="肯定">&nbsp;&nbsp;&nbsp;<input type="reset" value="取消"></tr>
            </table>
        </form>
    </body>
</html>

綜合數據庫_down_left_新添加學生_插入.jsp

<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫_down_left_新添加學生_插入</title>
    </head>
    <body>
        <%
            request.setCharacterEncoding("UTF-8");
            String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            Class.forName(driverName);
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=DB OF CWM";
            String userName="sa";
            String pwd="******";
            Connection conn=DriverManager.getConnection(dbURL,userName,pwd);
            String sql="insert into Student(Sno,Sname,Ssex,Sage,Sdept)values(?,?,?,?,?)";
            String sno=request.getParameter("Sno");
            String sname=request.getParameter("Sname");
            String ssex=request.getParameter("Ssex");
            int sage=Integer.parseInt(request.getParameter("Sage"));
            String sdept=request.getParameter("Sdept");
            PreparedStatement stmp=conn.prepareStatement(sql);
            stmp.setString(1,sno);
            stmp.setString(2,sname);
            stmp.setString(3,ssex);
            stmp.setInt(4,sage);
            stmp.setString(5,sdept);
            int n=stmp.executeUpdate();
            if(n==1){%>
            <h3>數據插入成功!</h3>
            <%
            }
            else{%>
                <h3>數據插入錯誤,請再次插入!</h3>
            <%}%>
            <%
                if(stmp!=null){
                    stmp.close();
                }
                if(conn!=null){
                    conn.close();
                }
            %>
    </body>
</html>

綜合數據庫_down_left_按條件刪除學生.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>按條件刪除學生</title>
    </head>
    <body>
        <h2>請輸入須要刪除的學生的信息:</h2><br>
        <form action="綜合數據庫_down_left_按條件刪除學生_刪除.jsp" method="post">
            <table>
                <tr><td>學號: </td><td><input type="text" name="Sno"></td></tr><br>
                <tr><td>姓名: </td><td><input type="text" name="Sname"></td></tr>
                <tr><td colspan="1"><input type="submit" value="確認">&nbsp;</td><td><input type="reset" value="取消"></td></tr>
            </table>
        </form>
    </body>
</html>

綜合數據庫_down_left_按條件刪除學生_刪除.jsp

<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫_down_left_按條件刪除學生_刪除</title>
    </head>
    <body>
        <%
            request.setCharacterEncoding("UTF-8");
            String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            Class.forName(driverName);
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=DB OF CWM";
            String userName="sa";
            String pwd="********";
            Connection conn=DriverManager.getConnection(dbURL,userName,pwd);
            String sql="delete from Student where Sno=? and Sname=?";
            PreparedStatement stmp=conn.prepareStatement(sql);
            String Sno=request.getParameter("Sno");
            String Sname=request.getParameter("Sname");
            stmp.setString(1, Sno);
            stmp.setString(2, Sname);
            int n=stmp.executeUpdate();
            if(n==1){%>
                此學生信息已被刪除!
            <%    
            }else{%>
                刪除失敗,請再次操做!
            <%
            }
            %>
            <%
                if(stmp!=null){
                    stmp.close();
                }
                if(conn!=null){
                    conn.close();
                }
            %>
    </body>
</html>

綜合數據庫_down_left_按條件修改學生.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫_down_left_按條件修改學生</title>
    </head>
    <body>
        請輸入須要修改信息的學生的學號和姓名:<br><br>
        <form action="綜合數據庫_down_left_按條件修改學生_顯示本來信息.jsp" method="post">
            學號: <input type="text" name="Sno"><br><br>
            姓名: <input type="text" name="Sname"><br><br>
            &nbsp;&nbsp;&nbsp;<input type="submit" value="確認">&nbsp;&nbsp;&nbsp;<input type="reset" value="取消">
        </form>
    </body>
</html>

綜合數據庫_down_left_按條件修改學生_顯示本來信息.jsp

<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>綜合數據庫_down_left_按條件修改學生_顯示本來信息</title>
    </head>
    <body>
        <%
            request.setCharacterEncoding("UTF-8");
            String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            Class.forName(driverName);
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=DB OF CWM";
            String userName="sa";
            String pwd="******";
            Connection conn=DriverManager.getConnection(dbURL,userName,pwd);
            String sql="select * from Student where Sno=? and Sname=?";
            String Sno=request.getParameter("Sno");
            String Sname=request.getParameter("Sname");
            session.setAttribute("Sno", Sno);
            session.setAttribute("Sname",Sname);
            PreparedStatement stmp=conn.prepareStatement(sql);
            stmp.setString(1, Sno);
            stmp.setString(2, Sname);
            ResultSet rs=stmp.executeQuery();
            if(rs.next()){
                String S_no=rs.getString("Sno");
                String S_name=rs.getString("Sname");
                String S_sex=rs.getString("Ssex");
                int S_age=rs.getInt("Sage");
                String S_dept=rs.getString("Sdept");
                if(rs!=null){
                    rs.close();
                }
                if(stmp!=null){
                    stmp.close();
                }
                if(conn!=null){
                    conn.close();
                }
                %>
                此學生信息以下:<br><br>
                <form action="綜合數據庫_down_left_按條件修改學生_更新數據.jsp" method="past">
                    <table>
                        <tr><td><input type="text" name="Sno" value=<%=S_no %>></td></tr>
                        <tr><td><input type="text" name="Sname" value=<%=S_name %>></td></tr>
                        <tr><td><input type="text" name="Ssex" value=<%=S_sex %>></td></tr>
                        <tr><td><input type="text" name="Sage" value=<%=S_age %>></td></tr>
                        <tr><td><input type="text" name="Sdept" value=<%=S_dept %>></td></tr>
                        <tr><td><input type="submit" value="確認"></td>&nbsp;<td><input type="reset" value="取消"></td></tr>
                    </table>
                </form>
        <%
            }
        %>
    </body>
</html>

綜合數據庫_down_left_按條件修改學生_更新數據.jsp

<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>綜合數據庫_down_left_按條件修改學生_更新數據</title>
    </head>
    <body>
        <%
            request.setCharacterEncoding("UTF-8");
            String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
            Class.forName(driverName);
            String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=DB OF CWM";
            String userName="sa";
            String pwd="*******";
            Connection conn=DriverManager.getConnection(dbURL,userName,pwd);
            String sql="update Student set Sno=?,Sname=?,Ssex=?,Sage=?,Sdept=? where Sno=? and Sname=?";
            String S_no=request.getParameter("Sno");
            String S_name=request.getParameter("Sname");
            String S_sex=request.getParameter("Ssex");
            int S_age=Integer.parseInt(request.getParameter("Sage"));
            String S_dept=request.getParameter("Sdept");
            String Sno=(String)session.getAttribute("Sno");
            String Sname=(String)session.getAttribute("Sname");
            PreparedStatement stmp=conn.prepareStatement(sql);
            stmp.setString(1, S_no);
            stmp.setString(2, S_name);
            stmp.setString(3, S_sex);
            stmp.setInt(4, S_age);
            stmp.setString(5, S_dept);
            stmp.setString(6, Sno);
            stmp.setString(7, Sname);
            int n=stmp.executeUpdate();
            if(n==1){%>
                數據更新成功<br>
            <%
            }
            else{%>
                數據更新失敗<br>
            <%
            }
            if(stmp!=null){
                stmp.close();
            }
            if(conn!=null){
                conn.close();
            }
            %>
    </body>
</html>

22:24:21

2018-10-02

相關文章
相關標籤/搜索