我是jsp的新手,当前遇到如下问题:
我想通过.jsp文件向一个access表中插入一条新的记录,表的一个属性是ID,类型是自动编号,可是怎么也插不进去,请高手赐教!
表的两个域是: ID (自动编号)name(文本)
//test1.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*"%>
<HTML>
<BODY bgcolor=pink>
<CENTER>
<BR>添加信息
<FORM action="test2.jsp" method=post>
<Input type="text" name="name">
<Input type="submit" value="确认">
<FORM>
</CENTER>
</BODY>
</HTML>
//test2.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*"%>
<HTML>
<BODY bgcolor=pink>
<%
Connection con;
Statement sql;
ResultSet rs;
String name=request.getParameter("name");
if(name==null)
{name=" ";}
byte n[]=name.getBytes("ISO-8859-1");
name=new String(n);
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1){}
try{ con=DriverManager.getConnection("jdbc:odbc:tt","","");
sql=con.createStatement();
String condition = "INSERT INTO 表1 VALUES("+",'"+name+"')";---->此处不知道该怎么写
sql.executeUpdate(condition);
}
catch(SQLException e2){}
%>
<p>提交成功
<FORM action="test3.jsp" method=post>
<BR>
<Input type="submit" value="查看信息">
</FORM>
<CENTER>
</CENTER>
</BODY>
</HTML>
//test3.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<HTML>
<BODY bgcolor=pink>
<CENTER>
<BR><p>
<%
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1){}
try{
con=DriverManager.getConnection("jdbc:odbc:tt","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM 表1");
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"ID");
out.print("<TH width=100>"+"name");
out.print("</TR>");
while(rs.next())
{
out.print("<TR>");
out.print("<TD >"+rs.getString("ID")+"</TD>");
out.print("<TD >"+rs.getString("name")+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
con.close();
}
catch(SQLException e2){}
%>
<FORM action="test3.jsp" method=post>
<BR>
<Input type="submit" value="刷新信息">
</FORM>
<FORM action="test1.jsp" method=post>
<BR><p>
<Input type="submit" value="返回主页">
</FORM>
</CENTER>
</BODY>
</HTML>