是什么意思呀?
newtushu.jsp
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<html>
<body bgcolor=cyan>
<font size=2>
添加新的数据到数据库:
<form action="newresult.jsp" method=post>
图书名:<br>
<input type="text" name="name" >
<br>编号:<br>
<input type="text" name="bianhao">
<br>出版社名:<br>
<input type="text" name="chubanshe">
<br>作者:<br>
<input type="text" name="zuozhe">
<br>类别:<br>
<input type="text" name="leibie">
<br>
<input type="submit" name="submit" value="提交添加">
<p>添加前的记录是:
<%
String name,bianhao,chubanshe,zuozhe,leibie;
Connection con;
Statement sql;
ResultSet rs;
String str="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\datafile\\tushu1.mdb";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try
{
con=DriverManager.getConnection(str,"","");
sql=con.createStatement();
rs=sql.executeQuery("Select * From tushu2");
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>");
bianhao=rs.getString("编号");
out.print("<TD>"+bianhao+"</TD>");
name=rs.getString("图书名");
out.print("<TD>"+name+"</TD>");
zuozhe=rs.getString("作者");
out.print("<TD>"+zuozhe+"</TD>");
chubanshe=rs.getString("出版社名");
out.print("<TD>"+chubanshe+"</TD>");
leibie=rs.getString("类别");
out.print("<TD>"+leibie+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
rs.close();
sql.close();
con.close();
;
}
catch(SQLException e1){}
%>
</form>
</font>
</body>
</html>
neuresult.jsp
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*" import ="java.util.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<html>
<body bgcolor=cyan>
<%
String name=request.Parameter("name");
if(name==null)
{
name="";
}
byte b[]=name.getBytes("ISO-8859-1");
name=new String(b);
String chubanshe=request.Parameter("chubanshe");
if(chubanshe==null)
{
chubanshe="";
}
byte c[]=chubanshe.getBytes("ISO-8859-1");
chubanshe=new String(c);
String zuozhe=request.Parameter("zuozhe");
if(zuozhe==null)
{
zuozhe="";
}
byte d[]=zuozhe.getBytes("ISO-8859-1");
zuozhe=new String(d);
String leibie=request.Parameter("leibie");
if(leibie==null)
{
leibie="";
}
byte e[]=leibie.getBytes("ISO-8859-1");
leibie=new String(e);
String bianhao=request.Parameter("bianhao");
if(bianhao==null)
{
bianhao="";
}
byte f[]=bianhao.getBytes("ISO-8859-1");
bianhao=new String(f);
Connection con=null;
Statement sql=null;
ResultSet rs=null;
String nbianhao,nname,nchubanshe,nleibie,nzuozhe;
String str="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\datafile\\tushu1.mdb";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException event){}
try
{
con=DriverManager.getConnection(str,"","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String condition="INSERT INTO tushu2 values "+"("+"'"+bianhao+"','"+name+"','"+zuozhe+"','"+chubanshe+"','"+leibie+"')";
sql.executeUpdate(condition);
%>
<p>添加后的记录:
<%
rs=sql.executeQuery("select * from tushu2");
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>");
nbianhao=rs.getString("编号");
out.print("<TD>"+nbianhao+"</TD>");
nname=rs.getString("图书名");
out.print("<TD>"+nname+"</TD>");
nzuozhe=rs.getString("作者");
out.print("<TD>"+nzuozhe+"</TD>");
nchubanshe=rs.getString("出版社名");
out.print("<TD>"+nchubanshe+"</TD>");
nleibie=rs.getString("类别");
out.print("<TD>"+nleibie+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
rs.close();
sql.close();
con.close();
}
catch(SQLException event){}
%>
</body>
</html>