
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY bgcolor=orange ><Font size=1>
 <FORM action="" Method=post>
  输入学生的学号：
 <Input type=text name=number>
 <Input type=submit name=g vale=提交>
 </FORM> 
 <%!  Connection con=null; //声明一个共享的连接对象
  %>
 <% //获取学号：
    String studentNumber=request.getParameter("number");
        if(studentNumber==null)
          {studentNumber="?";
          }
    byte b[]=studentNumber.getBytes("ISO-8859-1");
    studentNumber=new String(b);
    Statement sql=null; 
    ResultSet rs=null; 
    if(con==null)
      { try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           }
           catch(ClassNotFoundException e)
           {out.print(e);
           }
        try {con=DriverManager.getConnection("jdbc:odbc:manage","","");
          String condition="SELECT * FROM 成绩 WHERE 学号 = "+"'"+studentNumber+"'";
                 rs =sql.executeQuery(condition);
          }
        catch(SQLException e) 
          {out.print(e);
          }
      }
     else
      { synchronized(con)
        {  try { sql=con.createStatement();
             String condition="SELECT * FROM 成绩 WHERE 学号 = "+"'"+studentNumber+"'";
                 rs =sql.executeQuery(condition);
               }
          catch(SQLException e) 
               {out.print(e);
               }
        }
      }
    try {  out.print("<Table Border>");
         out.print("<TR>");
            out.print("<TH width=100>"+"学号");
            out.print("<TH width=100>"+"课程名称");
            out.print("<TH width=50>"+"成绩");
        out.print("</TR>");
       while(rs.next())
       { out.print("<TR>");
           String  number=rs.getString(1); 
             out.print("<TD >"+number+"</TD>"); 
           String  subjectName=rs.getString(2); 
             out.print("<TD >"+subjectName+"</TD>");
           String  chengji=rs.getString("成绩"); 
             out.print("<TD >"+chengji+"</TD>"); 
        out.print("</TR>") ; 
        }
      out.print("</Table>");
    }
   catch(SQLException e1) {}
 %>
<BR><A HREF="main.jsp">返回主页</A>
</FONT>
</BODY>
</HTML>
