JDBC技术学生身体体质信息管理系统

JDBC技术学生身体体质信息管理系统

1.主页面

<%@ 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>
<center><h1>学生身体体质信息管理系统</h1></center>
</body>
</html>

<%@ 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>
<br><br><br><br>
<p><a href="../select/select0.jsp" target="right">查询全部学生</a></p>
<p><a href="../insert/insert1.jsp" target="right">添加学生</a></p>
<p><a href="../delete/delete1.jsp" target="right">按条件删除学生</a></p>
<p><a href="../select/select1.jsp" target="right">按条件查询学生</a></p>
<p><a href="../update/update1.jsp" target="right">按条件修改学生</a></p>
</body>
</html>

<%@ 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="indextitle.jsp" scrolling="no">
<frame src="indexleft.jsp" scrolling="no">
</frameset>
</html>

2.添加信息

<%@ 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>
<p>请写入插入信息</p>
<hr>
<form action="insert2.jsp" method="post"><%//创建表单传输数据 %>
序号:&nbsp;<input type="text" name="id_in"><br><br>
姓名:&nbsp;<input type="text" name="name_in"><br><br>
性别:&nbsp;<input type="text" name="sex_in"><br><br>
年龄:&nbsp;<input type="text" name="age_in"><br><br>
体重:&nbsp;<input type="text" name="weight_in"><br><br>
身高:&nbsp;<input type="text" name="height_in"><br><br>
<input type="submit" value="确认">
&nbsp;<input type="reset" value="取消">
</form><br>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
       <%@ page import="java.sql.*" %>
<!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 driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/aaa";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql2="insert into biao1(id,name,sex,age,weight,height) values(?,?,?,?,?,?);";
%>
<%
request.setCharacterEncoding("UTF-8");//设置字符编码,避免乱码
if(request.getParameter("id_in")!=null&&request.getParameter("id_in").trim().length()>0&&
request.getParameter("name_in")!=null&&request.getParameter("name_in").trim().length()>0&&
request.getParameter("sex_in")!=null&&request.getParameter("sex_in").trim().length()>0&&
request.getParameter("age_in")!=null&&request.getParameter("age_in").trim().length()>0&&
request.getParameter("weight_in")!=null&&request.getParameter("weight_in").trim().length()>0&&
request.getParameter("height_in")!=null&&request.getParameter("height_in").trim().length()>0){
PreparedStatement pstmt=conn.prepareStatement(sql2);//对象
String id_in=request.getParameter("id_in");
String name_in=request.getParameter("name_in");
String sex_in=request.getParameter("sex_in");
String age_in=request.getParameter("age_in");
String weight_in=request.getParameter("weight_in");
String height_in=request.getParameter("height_in");//通过表单获取数据
int id_ins=Integer.parseInt(id_in);//将数据转换为相应类型
int age_ins=Integer.parseInt(age_in);
double weight_ins=Double.parseDouble(weight_in);
double height_ins=Double.parseDouble(height_in);
pstmt.setInt(1,id_ins);//将第一个占位符赋值
pstmt.setString(2,name_in);
pstmt.setString(3,sex_in);
pstmt.setInt(4,age_ins);
pstmt.setDouble(5,weight_ins);
pstmt.setDouble(6,height_ins);
int n=pstmt.executeUpdate();//执行insert,返回一个整数(即完成该操作的信息条数),该语句也可以完成delete语句与update语句
%>
<%
if(n>0) out.println("插入成功");
else out.println("插入失败");
%>
<%
pstmt.close();//释放资源,后创建的先释放
conn.close();}
else{out.println("输入违法");
conn.close();}
%>
</body>
</html>

3.删除信息

<%@ 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>
<p>请写入删除信息</p>
<hr>
<form action="delelte2.jsp" method="post"><%//创建表单传输数据 %>
姓名:&nbsp;<input type="text" name="name"><br><br>
性别:
&nbsp;男<input type="radio" name="sex" value="男">
&nbsp;女<input type="radio" name="sex" value="女"><br><br>
体重范围:<p>
最高体重:&nbsp;<input type="text" name="w1"><br><br>
最低体重:&nbsp;<input type="text" name="w2"><br><br>
<input type="submit" value="确认">
&nbsp;<input type="reset" value="取消">
</form><br>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
           <%@ page import="java.sql.*" %>
<!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 driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/aaa";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
%>
<%
request.setCharacterEncoding("UTF-8");//设置字符编码,避免乱码
String name=request.getParameter("name");
String sex=request.getParameter("sex");
String ww1=request.getParameter("w1");
String ww2=request.getParameter("w2");
String s="1=1 ";
if(!name.equals(""))s=s+" and name='"+name+"'";
if(sex!=null)s=s+" and sex='"+sex+"'";
double w1,w2;
if(!ww1.equals("")){w1=Double.parseDouble(ww1);s=s+" and weight>="+w1;}
if(!ww2.equals("")){w2=Double.parseDouble(ww2);s=s+" and weight<="+w2;}
String sql="delete from biao1 where "+s;
PreparedStatement pstmt=conn.prepareStatement(sql);
int n= pstmt.executeUpdate();
%>
<%
if(n>0) out.println("删除成功");
else out.println("删除失败");
%>
<%
pstmt.close();//释放资源,后创建的先释放
conn.close();
%>
</body>
</html>

4.查询信息

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="java.sql.*" %>
<!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 driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/aaa";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="select id,name,sex,age,weight,height from biao1;";//写出对数据库的操作语句,?表示占位符
%>
<%
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
ResultSet rs=pstmt.executeQuery();//执行select,返回一个结果集
rs.last();
%>
你要查询的共有<%=rs.getRow()%>人
<table border="2" width="650"><%//建立表格,显示数据 %>
<tr>
<td>记录条数</td>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>体重</td>
<td>身高</td>
</tr>
<%
rs.beforeFirst();//将信息放入表格
while(rs.next()){
%><tr>
<td><%=rs.getRow()%></td>
<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getInt(4)%></td>
<td><%=rs.getDouble(5)%></td>
<td><%=rs.getDouble(6)%></td>
</tr>
<%} %>
</table>
<%
rs.close();//释放资源,后创建的先释放
pstmt.close();
conn.close();
%>
</body>
</html>

<%@ 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>
<form action="select2.jsp" method="post"><%//创建表单传输数据 %>
<p>请选择想要查询的分数范围</p>
<hr>
最低体重:&nbsp;<input type="text" name="weight1"><br><br>
最高体重:&nbsp;<input type="text" name="weight2"><br><br>
<input type="submit" value="提交">
&nbsp;<input type="reset" value="取消">
</form><br>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
<!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 driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/aaa";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
String sql="select id,name,sex,age,weight,height from biao1 where weight>=? and weight<=?;";//写出对数据库的操作语句,?表示占位符
%>
<%
if(request.getParameter("weight1")!=null&&request.getParameter("weight1").trim().length()>0&&request.getParameter("weight2")!=null&&
request.getParameter("weight2").trim().length()>0){
String weight1=request.getParameter("weight1");//通过表单获取数据
String weight2=request.getParameter("weight2");
double wt1=Double.parseDouble(weight1);
double wt2=Double.parseDouble(weight2);//将数据转换为相应类型
PreparedStatement pstmt=conn.prepareStatement(sql);//对象
pstmt.setDouble(1, wt1);//将第一个占位符赋值
pstmt.setDouble(2, wt2);
ResultSet rs=pstmt.executeQuery();//执行select,返回一个结果集
rs.last();
%>
你要查询的共有<%=rs.getRow()%>人
<table border="2" width="650"><%//建立表格,显示数据 %>
<tr>
<td>记录条数</td>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>体重</td>
<td>身高</td>
</tr>
<%
rs.beforeFirst();//将信息放入表格
while(rs.next()){
%><tr>
<td><%=rs.getRow()%></td>
<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getInt(4)%></td>
<td><%=rs.getDouble(5)%></td>
<td><%=rs.getDouble(6)%></td>
</tr>
<%} %>
</table>
<%
rs.close();//释放资源,后创建的先释放
pstmt.close();
conn.close();
}
else
out.println("输入异常");
conn.close();
%>
</body>
</html>

5.修改信息

<%@ 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>
<p>请写入修改信息</p>
<hr>
<form action="update2.jsp" method="post"><%//创建表单传输数据 %>
姓名:&nbsp;<input type="text" name="name"><br><br>
性别:&nbsp;男<input type="radio" name="sex" value="男">
     &nbsp;女<input type="radio" name="sex" value="女"><br><br>
<input type="submit" value="确认">
&nbsp;<input type="reset" value="取消">
</form><br>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!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 driver = "com.mysql.jdbc.Driver";
		String url1 = "jdbc:mysql://localhost:3306/aaa";
		String url2 = "?user=root&password=2411030483";
		String url3 = "&useUnicode=true&characterEncoding=UTF-8";
		String url = url1 + url2 + url3;
		Class.forName(driver);
		Connection conn = DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
	%>
	<%
	request.setCharacterEncoding("UTF-8");
	String sex=request.getParameter("sex");
	String name=request.getParameter("name");
	session.setAttribute("sex",sex);
	session.setAttribute("name",name);

	String sql="select * from biao1 where sex=? and name=?";
	PreparedStatement pstmt=conn.prepareStatement(sql);
	pstmt.setString(1,sex);
	pstmt.setString(2,name);
	ResultSet rs = pstmt.executeQuery();
		if (rs.next()) {
			int id2 = rs.getInt(1);
			String name2 = rs.getString(2);
			String sex2 = rs.getString(3);
			int age2 = rs.getInt(4);
			double weight2 = rs.getDouble(5);
			double height2 = rs.getDouble(6);
			if (rs != null) {
				rs.close();
			}
			if (pstmt != null) {
				pstmt.close();
			} //释放资源,后创建的先释放
			if (conn != null) {
				conn.close();
			}
	%>
	<form action="update3.jsp" method="post">
		<table width="238" height="252" border="0">
			<tr>
				<td>学号</td>
				<td><input type="text" name="id2" value=<%=id2%>></td>
			</tr>
			<tr>
				<td>姓名</td>
				<td><input type="text" name="name2" value=<%=name2%>></td>
			</tr>
			<tr>
				<td>性别</td>
				<td><input type="text" name="sex2" value=<%=sex2%>></td>
			</tr>
			<tr>
				<td>年龄</td>
				<td><input type="text" name="age2" value=<%=age2%>></td>
			</tr>
			<tr>
				<td>体重</td>
				<td><input type="text" name="weight2" value=<%=weight2%>></td>
			</tr>
			<tr>
				<td>身高</td>
				<td><input type="text" name="height2" value=<%=height2%>></td>
			</tr>
			<tr align="center">
				<td><input type="submit" value="确认"></td>
				<td><input type="reset" value="取消"></td>
			</tr>
		</table>
	</form>
	<%
		} else {
			out.print("无合适条件");
			if (rs != null) {
				rs.close();
			}
			if (pstmt != null) {
				pstmt.close();
			} //释放资源,后创建的先释放
			if (conn != null) {
				conn.close();
			}}
	%>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
<!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 driver="com.mysql.jdbc.Driver";
String url1="jdbc:mysql://localhost:3306/aaa";
String url2="?user=root&password=2411030483";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driver);
Connection conn=DriverManager.getConnection(url);//实现注册驱动并建立数据库的连接
%>
<%
String sql="update biao1 set id=?,name=?,sex=?,age=?,weight=?,height=? where name=? and sex=?"; 
PreparedStatement pstmt=conn.prepareStatement(sql); 
request.setCharacterEncoding("UTF-8");
int id2=Integer.parseInt(request.getParameter("id2"));
String name2=request.getParameter("name2");
String sex2=request.getParameter("sex2");
int age2=Integer.parseInt(request.getParameter("age2"));
double weight2=Double.parseDouble(request.getParameter("weight2"));
double height2=Double.parseDouble(request.getParameter("height2"));
String name=(String)session.getAttribute("name");
String sex=(String)session.getAttribute("sex");
pstmt.setInt(1,id2);
pstmt.setString(2,name2);
pstmt.setString(3,sex2);
pstmt.setInt(4,age2);
pstmt.setDouble(5,weight2);
pstmt.setDouble(6,height2);
pstmt.setString(7,name);
pstmt.setString(8,sex);
int n=pstmt.executeUpdate();
if(n>0){%>
数据重写成功!<br>
<%}else{ %>
数据重写失败<br>
<%
}
if(pstmt!=null){pstmt.close();}//释放资源,后创建的先释放
if(conn!=null){conn.close();}
%>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值