考研成绩查询系统(jsp、mysql、java)


1、注:此考研成绩查询系统涉及到jsp、mysql、java的知识;成绩存放在数据库的graduate表score中。考生可以在页面上输入身份证号码和姓名,查询自己的成绩。系统在score表中找到身份证号和对应的成绩后,进一步检查身份证号码和姓名是否匹配,如果匹配则显示查询结果。 2、登陆页面: 考研成绩查询系统(jsp、mysql、java) - 不惊者 - 码农小屋
3、数据库:


 
数据库建表和用户:建数据库create database graduate default character set gbk;建表create table score(id_card varchar(18) primary key,name varchar(20),math float(6,2),english float(6,2),politics float(6,2),major float(6,2),total_score float(6,2))engine=MyISAM default charset=gbk;插入insert into score(id_card,name, math, english, politics, major)values('1','张三',130,70,69,120);insert into score(id_card,name, math, english, politics, major)values('2','李四',120,90,39,110);insert into score(id_card,name, math, english, politics, major)values('3','赵武',134,70,69,130);insert into score(id_card,name, math, english, politics, major)values('4','小胖',133,90,69,120);计算总分update score set total_score = math+english+politics+major;
创建用户grant all privileges on graduate.* to 'webuser'@'%'identified by 'webpass';grant all privileges on graduate.* to 'webuser'@'localhost' identified by 'webpass';flush privileges;
 
4、jsp源码

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>考研成绩查询系统</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String idcard = request.getParameter("idcard");
String name = request.getParameter("name");

if(idcard == null) idcard = "";
else idcard = idcard.trim();

if(name == null)name = "";
else name = name.trim();

request.setAttribute("idcard", idcard);
request.setAttribute("name", name);
%>

<h2>考研成绩查询系统</h2>
<form action="score.jsp" method="post">
<p>身份证:<input name="idcard" type="text" value="${idcard}"></p>
<p>姓&nbsp;&nbsp;名:<input name="name" type="text" value="${name}"></p>
<p style="padding-left:150px;">
<input type="submit" name="submit" value="查询">
</p>
</form>
<%
if(! ("".equals(idcard) && "".equals(name))){
Connection conn = null;
Statement state = null;
ResultSet rs = null;

try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/graduate?useUnicode=true&characterEncoding=gbk";
conn = DriverManager.getConnection(url, "webuser", "webpass");
state = conn.createStatement();
String sql = "select * from score where id_card='"+idcard+"'";
System.out.println("调试打印语句sql:" + sql);
rs = state.executeQuery(sql);

while(rs.next()){
String nameDB = rs.getString("name");

if(name.equals(nameDB)){
float math = rs.getFloat("math");
float english = rs.getFloat("english");
float politics = rs.getFloat("politics");
float major = rs.getFloat("major");
float total = rs.getFloat("total_score");
%>
<table width="580" border="0" cellspacing="1">
<tr align="center">
<th>身份证号码</th>
<th>姓名</th>
<th>数学</th>
<th>英语</th>
<th>政治</th>
<th>专业综合</th>
<th>总分</th>
</tr>
<tr align="center">
<td><%=idcard%></td>
<td><%=name%></td>
<td><%= math%></td>
<td><%= english%></td>
<td><%= politics%></td>
<td><%= major%></td>
<td><%= total%></td>
</tr>
</table>

<%
break;//跳出while循环
}else{
out.println("<p>身份证号与姓名不匹配! 身份证号:"+idcard+",姓名:"+name+"</p>");
}
rs.close();
state.close();
conn.close();
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{rs.close();}catch(Exception e1){
System.out.println("结果集ResultSet没有关闭"+"\n"+"异常信息为:");
}
try{state.close();}catch(Exception e2){
System.out.println("Statement没有关闭"+"\n"+"异常信息为:");
}
try{conn.close();}catch(Exception e3){
System.out.println("Connection没有关闭"+"\n"+"异常信息为:");
};
}
}
%>
</body>
</html>




注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com