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



更多相关文章

  1. [置顶] Android数据库框架GreenDao封装使用,易理解、易扩
  2. Android原生Contacts——界面和数据库
  3. [Android]如何导入已有的外部数据库
  4. Java操作数据库之jdbc【原生方式】
  5. Android复习练习十二(自定义ContentProvider实现其他应用操作本
  6. 如何从android的联系人姓名中获取联系人的号码?
  7. 实现基于注解(Annotation)的数据库框架(一)反射的基本了解
  8. 无法从Android中的Asset文件夹复制数据库
  9. Android之SQLite数据库篇

随机推荐

  1. PHP rss阅读器不起作用
  2. 学习成绩统计-【数组操作】
  3. 利用ApnsPHP包向IOS推送消息
  4. PHP中对用户密码进行加密
  5. 当将带有撇号的单词保存到数据库时,mysql_
  6. PHP的目录路径问题
  7. PHP调用内容DES加密的SOAP接口
  8. 返回key包含此字符串的值
  9. Yourphp系统发生错误
  10. 在HTTP 1.0中,状态码401的含义是什么;如果