输入学号后,输出的是所有学生的信息,但我只需要查询一个学生的信息。
<%@ page language="java" contentType="text/html;charset=utf-8" import="java.sql.*"%>
<table width="800px" border="0" align="center">
<tr height="100" bgcolor="#D9D816" align="center">
<td colspan="2" ><h1>学生信息管理系统</h1></td>
</tr>
<tr>
<td width="20%" height="380" bgcolor="#C7C6C6" valign="top">
<font color="#60579A" size="+1">
<h3>学生信息</h3>
<A href="../ex3/StuAddIpt.jsp">信息新增 </A><br>
<A href="../ex3/StuQryIpt.jsp">信息查询 </A><br>
<A href="../ex3/StuQryIpt.jsp">信息修改 </A><br>
<A href="../ex3/StuQryIpt.jsp">信息删除 </A><br>
</td>
<td width="81%" bgcolor="#F5E2E2" align="center" valign="top" >
<font color="#000000" >
<h2 >学生信息查询</h2>
<form name="frm" action="StuQryOpt.jsp" method="post">
<table width="460" border="1" cellpadding="2" cellspacing="0" bgcolor="#BCE1EF">
<tr>
<td width="61" align="center" valign="middle">学号</td>
<td colspan="3" valign="middle">
<%
String strStuID="";
String strStuName="";
String strSex="";
String strAge="";
String strDept="";
strStuID = request.getParameter("txtStuID");
strStuName = request.getParameter("txtStuName");
strSex = request.getParameter("rdoSex");
strAge = request.getParameter("slctAge");
strDept = request.getParameter("slctDept");
String url,sql;
Connection conn;
Statement stmt;
ResultSet rs;
sql = "select * from baseinfo";
if( request.getParameter("txtStuID") != null && !(request.getParameter("txtStuID")).trim().equals("") )
{
strStuID = request.getParameter("txtStuID");
sql = sql + " where sid = '" + strStuID + "'";
}
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
url ="jdbc:mysql://localhost:3306/student?serverTimezone=GMT%2B8";
conn=DriverManager.getConnection(url,"root","123456");
stmt=conn.createStatement();
rs = stmt.executeQuery(sql);
%>
<input type="text" name="tName" value="">
<input type="submit" value="确定">
<input type="reset" value="取消">
</form>
</td>
</tr>
<%
rs.close();
stmt.close();
conn.close();}
catch(Exception e){
out.println(e);
}
%>
</table>
<tr height="60" bgcolor="#3399FF" align="center" >
<td colspan="2" ><h1>版权声明</h1></td>
</tr>
</table>
</body>
可能没有进去if,然后没有拼接上where条件,所以就全差出来了