<%@ 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>姓 名:<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>
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。