<%@page language = "java"%>
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%
//下面四句代码用于连接数据源
String url = "jdbc:odbc:student"; //定义数据源
String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; //定义jdbc-odbc驱动
Class.forName(driver); //装载驱动
Connection conn = DriverManager.getConnection(url); //连接数据源
//获取数据库中的记录
Statement sqlStatement = conn.createStatement(); //定义sql语句对象
String stuNum = request.getParameter("stuNum"); //得到reg1.jsp中stuNum的值
String stuName = request.getParameter("stuName"); //得到reg1.jsp中stuName的值
String sex = request.getParameter("sex"); //得到reg1.jsp中sex的值
String qq = request.getParameter("qq"); //得到reg1.jsp中QQ的值
String ficq = request.getParameter("ficq"); //得到reg1.jsp中FICQ的值
String email = request.getParameter("email"); //得到reg1.jsp中email的值
String userName = request.getParameter("userName"); //得到reg1.jsp中useName的值
String password1 = request.getParameter("password1"); //得到reg1.jsp中password的值
String sql;
sql = "insert into student(stuNum,stuName,sex,qq,ficq,email,userName,password) values ("
+ stuNum + ",'" + stuName + "','" + sex + "','" + "'," + qq +
"," + ficq + ",'" + email + "','" + userName + "','" + password1 + "')";
//Statement smt = conn.createStatement();
out.println(sql);
sqlStatement.executeUpdate(sql);
//查询语句操作
//sql = "select * from student where stuNum = 22";
//ResultSet rs = sqlStatement.executeQuery(sql);
//if (rs.next()) {
// String r = rs.getString("stuNum");
// out.println(r);
//}
sqlStatement.close();
conn.close();
%>
当注释//sqlStatement.executeUpdate(sql);时,打印出"insert into student (stuNum,stuName,sex,qq,ficq,email,userName,password) values (222,'jin','null','',222,22,'22','jin','jin') ",
可以进行查询操作。进行插入操作出错:无法显示网页。
请问这是怎么回事?
[求助]无法进行数据库插入操作!(附代码)