下载链接:https://download.csdn.net/download/OrdnAry/12394141
所有JSP相关代码 "https://github.com/13137565955/JSP-MySQL"
1.首页面shujuku.jsp
shujuku.jsp
<%@ page contentType ="text/html ;charset = UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<HTML>
<head>
<meta http-equil="Content-Type" content="text/html:charset=UTF-8">
<title>数据库</title>
</head>
<BODY bgcolor="pink">
<td>
<table border="1" bgcolor="yellow" align="center">
<tr>
<th width="80" align="center">学号</th>
<th width="80" align="center">姓名</th>
<th width="80" align="center">性别</th>
<th width="80" align="center">年龄</th>
<th width="80" align="center">出生地</th>
<th width="80" align="center">功能</th>
</tr>
</td>
<% try { Class.forName("com.mysql.jdbc.Driver");}
catch(ClassNotFoundException e) {
out.print(e);
}
Connection con;
Statement stmt;
ResultSet rs;
String uri=
"jdbc:mysql://localhost:3306/student?" +
"user=root&password=root&characterEncoding=utf-8";
con = DriverManager.getConnection(uri);
stmt = con.createStatement();
String sql="select *from student order by 学号";
rs=stmt.executeQuery(sql);
%><center>
<a href="tianjia.jsp"><h2>添加数据</h2></a></center>
<FORM action = "chaxunNumber.jsp" Method ="post">
<h3 align="center">输入学号查询数据:<Input type="text" name = "idcard" >
<Input type= submit name= "tijiao1" value= "提交">
</Form>
<FORM action = "chaxunName.jsp" Method ="post">
<h3 align="center">输入姓名查询数据:<Input type="text" name = "name" >
<Input type= submit name= "tijiao2" value= "提交">
</Form>
<%
while (rs.next()){
%>
<tr>
<td><%=rs.getString("学号")%></td>
<td><%=rs.getString("姓名")%></td>
<td><%=rs.getString("性别")%></td>
<td><%=rs.getString("年龄")%></td>
<td><%=rs.getString("出生地")%></td>
<td>
<a href="xiugai.jsp?id=<%out.print(rs.getString(1));%>">修改
<a href="shanchu.jsp?id=<%out.print(rs.getString(1));%>">删除</a>
</tr>
<%}
con.close();%>
</table></BODY></HTML>
2.添加显示页面 tianjia.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数据库的添加</title>
</head>
<body bgcolor="pink">
<form action="tianjiayunxing.jsp" method="post" >
<h2 align="center">输入要添加的学生信息</h2>
<hr>
<table border="0" width="220" align="center">
<tr>
<td>学号:</td>
<td><input type="text" name="idcard"></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="text" name="sex"></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>出生地:</td>
<td><input type="text" name="address"></td>
</tr>
<tr align="center">
<td colspan="2" align="center">
<input name="sure" type="submit" value="提交">
<input name="clear" type="reset" value="清除">
</td>
</tr>
</table>
<hr><center>
<h3 align="center">如果不想添加学生请点击返回数据库</h3>
<a href="shujuku.jsp">返回数据库</a> </center>
</form></body></html>
2.1添加的逻辑运行界面 tianjiayunxing.jsp
<%@ page contentType ="text/html;charset = UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<HTML>
<head>
<meta http-equil="Content-Type" content="text/html:charset=UTF-8">
<title>添加数据库</title>
</head>
<BODY bgcolor="pink">
<hr>
<br>
<% String idcard =new String(request.getParameter("idcard").getBytes("ISO-8859-1"));
String name =new String( request.getParameter("name").getBytes("ISO-8859-1"));
String sex = new String( request.getParameter("sex").getBytes("ISO-8859-1"));
String age = new String( request.getParameter("age").getBytes("ISO-8859-1"));
String address = new String( request.getParameter("address").getBytes("ISO-8859-1"));
try { Class.forName("com.mysql.jdbc.Driver");}
catch(ClassNotFoundException e) {
out.print(e);
}
Connection con;
Statement stmt;
ResultSet rs;
String uri=
"jdbc:mysql://localhost:3306/student?" +
"user=root&password=root&characterEncoding=utf-8";
con = DriverManager.getConnection(uri);
stmt = con.createStatement();
String sql="insert into student values('"+idcard+"','"+name+"','"+sex+"',"+age+",'"+address+"')";
stmt.executeUpdate(sql);
con.close();
%>
<center>
<h1 align="center">已添加学生信息</h1>
<a href="shujuku.jsp"><h2>点击返回数据库查看</h2></a> </center>
</BODY></HTML>
3.修改显示页面 xiugai.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数据库的修改</title>
</head>
<body bgcolor="pink">
<% String id =request.getParameter("id"); %>
<form action="xiugaiyunxing.jsp" method="post" >
<h2 align="center">输入要修改的学生信息</h2>
<hr>
<table border="0" width="220" align="center">
<tr>
<td>学号:</td>
<td><input type="text" name="idcard"></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="text" name="sex"></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>出生地:</td>
<td><input type="text" name="address"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="sure" type="submit" value="提交">
<input name="clear" type="reset" value="清除">
</td>
</tr>
<input type="hidden" name="id" value="<%=id%>">
</table>
<hr><center>
<h3 align="center">如果不想修改学生信息请点击返回数据库</h3>
<a href="shujuku.jsp">返回数据库</a> </center>
</form></body></html>
4.修改逻辑运行界面 xiugaiyunxing.jsp
<%@ page contentType ="text/html;charset = UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<HTML>
<head>
<meta http-equil="Content-Type" content="text/html:charset=UTF-8">
<title>修改数据库</title>
</head>
<BODY bgcolor="pink">
<hr>
<br>
<% String id=new String(request.getParameter("id").getBytes("ISO-8859-1"));
String idcard =new String(request.getParameter("idcard").getBytes("ISO-8859-1"));
String name =new String(request.getParameter("name").getBytes("ISO-8859-1"));
String sex = new String(request.getParameter("sex").getBytes("ISO-8859-1"));
String age = new String(request.getParameter("age").getBytes("ISO-8859-1"));
String address = new String( request.getParameter("address").getBytes("ISO-8859-1"));
try { Class.forName("com.mysql.jdbc.Driver");}
catch(ClassNotFoundException e) {
out.print(e);
}
Connection con;
Statement stmt;
ResultSet rs;
String uri=
"jdbc:mysql://localhost:3306/student?" +
"user=root&password=root&characterEncoding=utf-8";
con = DriverManager.getConnection(uri);
stmt = con.createStatement();
String sql="update student set 学号='"+idcard+"',姓名='"+name+"',性别='"+sex+"',年龄="+age+",出生地='"+address+"'where 学号="+id+";";
stmt.executeUpdate(sql);
con.close();
%>
<center>
<h1 align="center">已修改学生信息</h1>
<a href="shujuku.jsp"><h2>点击返回数据库查看</h2></a> </center>
</BODY></HTML>
5.删除界面 shanchu.jsp
<%@page contentType ="text/html;charset = UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<HTML>
<head>
<meta http-equil="Content-Type" content="text/html:charset=UTF-8">
<title>删除数据库</title>
</head>
<BODY bgcolor="pink">
<% String idcard =request.getParameter("id");
try { Class.forName("com.mysql.jdbc.Driver");}
catch(ClassNotFoundException e) {
out.print(e);
}
Connection con;
Statement stmt;
ResultSet rs;
String uri=
"jdbc:mysql://localhost:3306/student?" +
"user=root&password=root&characterEncoding=utf-8";
con = DriverManager.getConnection(uri);
stmt = con.createStatement();
String sql1="delete from student where 学号='"+idcard+"'";
stmt.executeUpdate(sql1);
con.close();%>
<center>
<h1 align="center">已删除学生信息</h1>
<a href="shujuku.jsp"><h2>点击返回数据库查看</h2></a> </center>
</BODY></HTML>
6.用学号查询页面 chaxunNumber.jsp
<%@page contentType ="text/html;charset = UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<HTML>
<head>
<meta http-equil="Content-Type" content="text/html:charset=UTF-8">
<title>查询数据库</title>
</head>
<BODY bgcolor="pink">
<h2 align="center">你的查询结果如下</h2>
<hr>
<table border="1" bgcolor="yellow" align="center">
<tr>
<th width="80" align="center">学号</th>
<th width="80" align="center">姓名</th>
<th width="80" align="center">性别</th>
<th width="80" align="center">年龄</th>
<th width="80" align="center">出生地</th>
<th width="80" align="center">功能</th>
</tr>
<% String idcard =new String(request.getParameter("idcard").getBytes("ISO-8859-1"));
try { Class.forName("com.mysql.jdbc.Driver");}
catch(ClassNotFoundException e) {
out.print(e);
}
Connection con;
Statement stmt;
ResultSet rs;
String uri=
"jdbc:mysql://localhost:3306/student?" +
"user=root&password=root&characterEncoding=utf-8";
con = DriverManager.getConnection(uri);
stmt = con.createStatement();
String sql="select *from student where 学号 like'"+idcard+"%' order by 学号";
rs=stmt.executeQuery(sql);
while (rs.next()){
%>
<tr>
<td><%=rs.getString("学号")%></td>
<td><%=rs.getString("姓名")%></td>
<td><%=rs.getString("性别")%></td>
<td><%=rs.getString("年龄")%></td>
<td><%=rs.getString("出生地")%></td>
<td>
<a href="xiugai.jsp?id=<%out.print(rs.getString(1));%>">修改
<a href="shanchu.jsp?id=<%out.print(rs.getString(1));%>">删除</a>
</tr>
<%}
rs.close();
con.close();%>
</table>
<hr>
<center>
<a href="shujuku.jsp">点击返回数据库查看</a> </center>
</BODY></HTML>
7.用名字查询页面 chaxunName.jsp
<%@page contentType ="text/html;charset = UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<HTML>
<head>
<meta http-equil="Content-Type" content="text/html:charset=UTF-8">
<title>查询数据库</title>
</head>
<BODY bgcolor="pink">
<h2 align="center">你的查询结果如下</h2>
<hr>
<table border="1" bgcolor="yellow" align="center">
<tr>
<th width="80" align="center">学号</th>
<th width="80" align="center">姓名</th>
<th width="80" align="center">性别</th>
<th width="80" align="center">年龄</th>
<th width="80" align="center">出生地</th>
<th width="80" align="center">功能</th>
</tr>
<% String name =new String(request.getParameter("name").getBytes("ISO-8859-1"));
try { Class.forName("com.mysql.jdbc.Driver");}
catch(ClassNotFoundException e) {
out.print(e);
}
Connection con;
Statement stmt;
ResultSet rs;
String uri=
"jdbc:mysql://localhost:3306/student?" +
"user=root&password=root&characterEncoding=utf-8";
con = DriverManager.getConnection(uri);
stmt = con.createStatement();
String sql="select *from student where 姓名 like'"+name+"%' order by 学号";
rs=stmt.executeQuery(sql);
while (rs.next()){
%>
<tr>
<td><%=rs.getString("学号")%></td>
<td><%=rs.getString("姓名")%></td>
<td><%=rs.getString("性别")%></td>
<td><%=rs.getString("年龄")%></td>
<td><%=rs.getString("出生地")%></td>
<td>
<a href="xiugai.jsp?id=<%out.print(rs.getString(1));%>">修改
<a href="shanchu.jsp?id=<%out.print(rs.getString(1));%>">删除</a>
</tr>
<%}
rs.close();
con.close();%>
</table>
<hr>
<center>
<a href="shujuku.jsp">点击返回数据库查看</a> </center>
</BODY></HTML>