package a4;
import java.sql.*;
public class DataBaseInquire
{  String keyword;
   public DataBaseInquire()
    {keyword="";
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e){}
    }
   public void setKeyword(String s)
    {keyword=s;
      try{byte b[]=keyword.getBytes("ISO-8859-1");
          keyword=new String(b);
         }
      catch(Exception e)
         { }
    }
  public StringBuffer byKeywordInquire()
    { String number,xingming;
      Connection con=null;
      Statement sql=null;
      ResultSet rs=null;
      StringBuffer buffer=new StringBuffer();  
      String gonghao;
      float weight,height;
      try{ con=DriverManager.getConnection("jdbc:odbc:sun2","sa","");
           sql=con.createStatement();
           String condition="SELECT * FROM emp" ;
           rs=sql.executeQuery(condition);
            buffer.append("<Table Border>");
            buffer.append("<TR>");
            buffer.append("<TH width=100>"+"工号");
            buffer.append("<TH width=50>"+"姓名");
            buffer.append("<TH width=50>"+"身高");
            buffer.append("<TH width=50>"+"体重");
            buffer.append("</TR>");
        while(rs.next())
           { buffer.append("<TR>");
             gonghao=rs.getString(1); 
             buffer.append("<TD >"+gonghao+"</TD>"); 
             xingming=rs.getString(2); 
             buffer.append("<TD >"+xingming+"</TD>"); 
             height=rs.getFloat("身高"); 
             buffer.append("<TD >"+height+"</TD>");
             weight=rs.getFloat("体重"); 
             buffer.append("<TD >"+weight+"</TD>");   
             buffer.append("</TR>") ;          
            }
          buffer.append("</Table>");
          con.close();
          return buffer;
      }
    catch(SQLException e)
          {return new StringBuffer("无法建立查询");
          }
   } 
}
