表单:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>addStuInfo.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head>
<body>
<div align="center"><font aize="5">新增学生记录</font></div>
<hr size="1">
<div align="center">
<form action="addStuInfo.jsp" method="post" name="form1">
学号:<input type="text" name="sno" size="15"><br>
姓名:<input type="text" name="sname" size="15"><br>
性别:<input type="text" name="ssex" size="15"><br>
年龄:<input type="text" name="sage" size="15"><br>
籍贯:<input type="text" name="sjiguan" size="15"><br>
<p><input type="submit" value="提交"> <input type="reset" value="重置">
</form>
</body>
</html>处理表单的jsp页面
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>处理增加的学生记录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<%
String no=request.getParameter("sno");
String name=request.getParameter("sname");
String sex=request.getParameter("ssex");
String age=request.getParameter("sage");
String jiguan=request.getParameter("sjiguan");
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DataBase=student";
Connection conn=DriverManager.getConnection(url,"sa","sa");
Statement smt=conn.createStatement();
String SqlStr="insert into student_info(sno,sname,ssex,sage,sjiguan)";
SqlStr=SqlStr+"values('"+no+"','"+name+"','"+sex+"','"+age+"','"+jiguan+"')";
smt.executeUpdate(SqlStr);
smt.close();
conn.close();
}catch(SQLException e)
{
e.getMessage();
}
%>
</body>
</html>
运行完毕后,没有错误显示,在sql server200 中没有显示出来
高手请进,帮帮忙!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>addStuInfo.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head>
<body>
<div align="center"><font aize="5">新增学生记录</font></div>
<hr size="1">
<div align="center">
<form action="addStuInfo.jsp" method="post" name="form1">
学号:<input type="text" name="sno" size="15"><br>
姓名:<input type="text" name="sname" size="15"><br>
性别:<input type="text" name="ssex" size="15"><br>
年龄:<input type="text" name="sage" size="15"><br>
籍贯:<input type="text" name="sjiguan" size="15"><br>
<p><input type="submit" value="提交"> <input type="reset" value="重置">
</form>
</body>
</html>处理表单的jsp页面
<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>处理增加的学生记录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<%
String no=request.getParameter("sno");
String name=request.getParameter("sname");
String sex=request.getParameter("ssex");
String age=request.getParameter("sage");
String jiguan=request.getParameter("sjiguan");
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DataBase=student";
Connection conn=DriverManager.getConnection(url,"sa","sa");
Statement smt=conn.createStatement();
String SqlStr="insert into student_info(sno,sname,ssex,sage,sjiguan)";
SqlStr=SqlStr+"values('"+no+"','"+name+"','"+sex+"','"+age+"','"+jiguan+"')";
smt.executeUpdate(SqlStr);
smt.close();
conn.close();
}catch(SQLException e)
{
e.getMessage();
}
%>
</body>
</html>
运行完毕后,没有错误显示,在sql server200 中没有显示出来
高手请进,帮帮忙!
String sql = "insert into aaa values('123')";
而sqlServer里面是这样:sql="insert into [aaa] values('123')";它的关键字得用[]括起来
不知道能不能帮你解决问题