package ppp;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Inquire extends HttpServlet
{  public void init(ServletConfig config) throws ServletException
    {super.init(config);
    }
   //通过Post方法按名字查询记录：
  public  void doPost(HttpServletRequest request,HttpServletResponse response) 
                        throws ServletException,IOException
  { 
    response.setContentType("text/html;charset=GB2312");//设置响应的MIME类型。
    PrintWriter out=response.getWriter();
    out.println("<HTML>"); 
    out.println("<BODY>");
  //获取提交的姓名：
    
    String name=request.getParameter("name");
          if(name==null)
            {name="";
            }
     byte c[]=name.getBytes("ISO-8859-1");
     name=new String(c);
    String number,xingming;
    Connection con=null;
    Statement sql=null;
    ResultSet rs=null;
    int math,english,physics;
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e){}
       try
      {    con=DriverManager.getConnection("jdbc:odbc:sun","sa","");
           sql=con.createStatement();
           String condition="SELECT * FROM student WHERE xingming = "+"'"+name+"'";
           rs=sql.executeQuery(condition);
           out.print("<Table Border>");
            out.print("<TR>");
            out.print("<TH width=100>"+"Number");
            out.print("<TH width=100>"+"Name");
            out.print("<TH width=50>"+"Math");
            out.print("<TH width=50>"+"English");
            out.print("<TH width=50>"+"Phsics");
            out.print("</TR>");
       	    while(rs.next())
           { out.print("<TR>");
             number=rs.getString(1); 
             out.print("<TD >"+number+"</TD>"); 
             xingming=rs.getString(2); 
             //byte d[]=name.getBytes("ISO-8859-1");
     		 //xingming=new String(d);
             out.print("<TD >"+xingming+"</TD>");
             math=rs.getInt("sx"); 
             out.print("<TD >"+math+"</TD>"); 
             english=rs.getInt("yy"); 
             out.print("<TD >"+english+"</TD>");
             physics=rs.getInt("wl"); 
             out.print("<TD >"+physics+"</TD>");   
            out.print("</TR>") ;          
            }
       out.print("</Table>");
      con.close();
     }
    catch(SQLException e)
          {
          }
      out.println("</BODY>");
      out.println("</HTML>");
  }
  
  public void doGet(HttpServletRequest request,HttpServletResponse response) 
                        throws ServletException,IOException
  { doPost(request,response);}
}