代码如下
<%@ page language="java" import="java.sql.*" %>
String userName = request.getParameter("userName");
String userPwd = request.getParameter("userPwd");
String userAge = request.getParameter("userAge");
String userID = request.getParameter("userID");
<%
String sql = "";
sql = "insert into table_user(";
sql += "userName,userPwd,userAge,userID";
sql += ") values (";
sql += "'" + userName + "',";
sql += "'" + userPwd + "',";
sql += "'" + userAge + "',";
sql += "'" + userID + "'";
sql += ")";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:db","","");
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
conn.close();
%>
------解决方案--------------------
应该是这样的:
<%@ page language="java" import="java.sql.*" %>
<%
String userName = request.getParameter("userName");
String userPwd = request.getParameter("userPwd");
String userAge = request.getParameter("userAge");
String userID = request.getParameter("userID");
String sql = "";
sql = "insert into table_user(";
sql += "userName,userPwd,userAge,userID";
sql += ") values (";
sql += "'" + userName + "',";
sql += "'" + userPwd + "',";
sql += "'" + userAge + "',";
sql += "'" + userID + "'";
sql += ")";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:db","","");
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
conn.close();
%>