<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY bgcolor=pink ><Font size=4>
<% //获取提交的书号：
    String number=request.getParameter("shuhao");
          if(number==null)
            {number="";
            }
     byte b[]=number.getBytes("ISO-8859-1");
     number=new String(b);
    //获取提交的书名：
    String name=request.getParameter("shuming");
          if(name==null)
            {name="";
            }
     byte c[]=name.getBytes("ISO-8859-1");
     name=new String(c);
    //获取提交的出版社
    String chuban=request.getParameter("chubanshe");
          if(chuban==null)
            {chuban=""; }
     byte h[]=chuban.getBytes("ISO-8859-1");
     chuban=new String(h);
    //获取提交的作者姓名
    String author=request.getParameter("zuozhe");
          if(author==null)
            {author=""; }
     byte x[]=author.getBytes("ISO-8859-1");
     author=new String(x);
    //获取提交的出版日期
     String rq=request.getParameter("riqi");
          if(rq==null)
            {rq=""; } 
     byte k[]=rq.getBytes("ISO-8859-1");
     rq=new String(k);
    Connection con=null;
    Statement sql=null;
    ResultSet rs=null;
    try{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
	}
    catch(ClassNotFoundException event){}
    try {
		con=DriverManager.getConnection("jdbc:odbc:aaa","sa","");
       		sql=con.createStatement();
       		String condition=
       		"INSERT INTO books VALUES"+"("+"'"+number+"','"+name+"',"+chuban+","+author+","+rq+")";
       		sql.executeUpdate(condition); //执行添加操作
       //显示添加新记录后表中的记录
%>
<P>添加新记录后的表：
<%
       		rs=sql.executeQuery("SELECT * FROM books ORDER BY 书号 ");
       		out.print("<Table Border>");
           	out.print("<TR>");
            	out.print("<TH width=100>"+"书号");
            	out.print("<TH width=100>"+"书名");
            	out.print("<TH width=100>"+"出版社");
            	out.print("<TH width=100>"+"作者");
            	out.print("<TH width=100>"+"出版日期");
            	out.print("</TR>");
       		while(rs.next())
           	{    
			out.print("<TR>");
                	String shuhao=rs.getString(1);
                 	out.print("<TD >"+shuhao+"</TD>"); 
                	String shuming=rs.getString(2);
                 	out.print("<TD >"+shuming+"</TD>");
                	String chubanshe=rs.getString(3); 
                 	out.print("<TD >"+chubanshe+"</TD>"); 
                	String zuozhe=rs.getString(4); 
                 	out.print("<TD >"+zuozhe+"</TD>");
                	String riqi=rs.getString(5); 
                 	out.print("<TD >"+riqi+"</TD>"); 
            		out.print("</TR>") ;  
         	}
       		out.print("</Table>");
      		con.close();
     	}
    	catch(SQLException event){ }
 %>
</FONT>
</BODY>
</HTML>




