package a1;
import java.sql.*;
public class BuyBook
{   long id=0;
    String order_number,
           book_name;
    Connection con;
    Statement sql; 
    ResultSet rs;
    public BuyBook()
    {  //加载桥接器：
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e){}
    }
  //设置属性值、获取属性值的方法：
  public void setId(long n)
    {id=n;
    }
  public long getId()
    {return id;
    }
  public void setBook_name(String name)
    {  book_name=name;
    }
  public String getBook_name()
    {return book_name;
    }
  public void setOrder_number(String number)
    {  order_number=number;
    }
  public String getOrder_number()
    {return order_number;
    }
  //通过书的id号查询数据库的book表：
   public StringBuffer getMessageBybook_id()
    {
     StringBuffer buffer=new StringBuffer();
     try{
         con=DriverManager.getConnection("jdbc:odbc:shop","","");
         sql=con.createStatement();
          String condition="SELECT * FROM book WHERE id = "+id;
          rs=sql.executeQuery(condition);
         buffer.append("<Table Border><FONT size=1> ");
            buffer.append("<TR>");
       buffer.append("<TH width=50>"+"<Font size=1>"+"id"+"</FONT>");
       buffer.append("<TH width=50>"+"<Font size=1>"+"订购号"+"</FONT>");
       buffer.append("<TH width=70>"+"<Font size=1>"+"书名"+"</FONT>");
       buffer.append("<TH width=60>"+"<Font size=1>"+"作者"+"</FONT>");
       buffer.append("<TH width=60>"+"<Font size=1>"+"出版社"+"</FONT>");
       buffer.append("<TH width=50>"+"<Font size=1>"+"出版时间"+"</FONT>");
       buffer.append("<TH width=20>"+"<Font size=1>"+"价钱"+"</FONT>");
       buffer.append("<TH width=50>"+"<Font size=1>"+"分类"+"</FONT>");
       buffer.append("</TR>");
           while(rs.next())
           { order_number=rs.getString(2);
             book_name=rs.getString(3);
             String 作者=rs.getString(4);
             String 出版社=rs.getString(5);
             Date 时间=rs.getDate(6);
             String 价格=rs.getString("price");
             String 分类=rs.getString("category"); 
             buffer.append("<TR>");
             buffer.append("<TD >"+"<Font size=1>"+rs.getLong(1)+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+order_number+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+book_name+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+作者+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+出版社+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+时间+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+价格+"</FONT>");
             buffer.append("<TD >"+"<Font size=1>"+分类+"</FONT>");
             buffer.append("</TR>");
          } 
        buffer.append("</TABLE>");
        buffer.append("</FONT>");
        con.close();
        return buffer;
       }
     catch(SQLException e)
       { return buffer;
       }
    }
}