考研成績查詢系統(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