新手~求助一题JSP关于插入数据到表的题!谢谢各位咯~
五,已经存在数据源:db,数据库里面存在表:student,
相应的字段如下:
Name varchar(20)
Sex varchar(20)
Age varchar(20)
English varchar(20)
Chinese varchar(20)
建立一张表单程序insert.htm和相应的jsp程序insert.jsp,能够输入上面5个字段的值,插入数据库。(25分)
我是这样改的呢~帮我再修改下~~
程序insert.htm
---------------------------------------------------------------------
<%@ page contentType= "text/html; charset=gb2312 " import = "java.sql.* " %>
<% request.setCharacterEncoding( "gb2312 "); %>
<html>
<body>
请输入您要添加的数据
<hr>
<form action= "ch9-7b.jsp " method= "post ">
input data <input type= "text " name= "name1 " > <br>
input data <input type= "text " name= "name2 " > <br>
input data <input type= "text " name= "name3 " > <br>
input data <input type= "text " name= "name4 " > <br>
input data <input type= "text " name= "name5 " > <br>
<input type= "submit " value= "提交 ">
</body>
</html>
程序cinsert.jsp
---------------------------------------------------------
<%@ page contentType= "text/html; charset=gb2312 " import = "java.sql.*“ %>
<% request.setCharacterEncoding( "gb2312 "); %>
<html>
<body>
<%
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
Connection con = DriverManager.getConnection( "jdbc:odbc:db ");
Statement smt = con.createStatement();
String jspname=request.getParameter( "name ");
String sql;
sql = "insert into grades(姓名) values( ' "+jspname+ " '); ";
smt.execute(sql);
con.close();
%>
</body>
</html>
------解决方案--------------------import = "java.sql.*“ %> 这后面一个引号出问题了 应该import = "java.sql.* "