成都 三甲医院 体检:jsp+access的问题,高手请进

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 00:53:21
我相向表里插入条记录,各位高手帮我看看哪错了
<%@ page contentType="text/html; charset="GB2312" language="java" import="java.sql.*;" %>
<html>
<head>
<meta-equiv="Content-Type" content="text/html; charset=gb2312">
<title>提交</title>
</head>
<body>
<%! String sql; %>
<%
String name=request.getParameter("username").trim();
name=new String(name.getBytes("ISO8859_1"),"GBK");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:may");
Statement stmt=con.createStatement();
sql="insert into 表1(username)";
sql=sql+"values('"+name+"');
stmt.executeUpdate(sql);
stmt.close;
conn.close;
%>
</body>
</html>
错误显示
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /6.jsp(1,49) equal symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:90)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:193)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:143)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:156)
org.apache.jasper.compiler.ParserController.getPageEncodingForJspSyntax(ParserController.java:452)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:386)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:170)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

--------------------------------------------------------------------------------

Apache Tomcat/5.0.28
另外, .trim()是什么,有什么作用

你这错误太多了
我给你改好了!
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" %>
<html>
<head>
<meta-equiv="Content-Type" content="text/html; charset=gb2312">
<title>提交</title>
</head>
<body>
<%! String sql; %>
<%
String name=request.getParameter("username").trim();
name=new String(name.getBytes("ISO8859_1"),"GBK");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:may");
Statement stmt=con.createStatement();
sql="insert into 表1(username)";
sql=sql+"values('"+name+"');
stmt.executeUpdate(sql);
stmt.close();
con.close();
%>
</body>
</html>

trim()表示去除字符串首尾空格。

1. 这两句话有问题
sql="insert into 表1(username)";
sql=sql+"values('"+name+"');
SQL语句关键字之间要有空格的。还少了结束的引号。
sql="insert into 表1 (username) ";
sql=sql+" values('"+name+"')";

2.trim()表示去除字符串首尾空格。

stmt.close,conn.close应该是stmt.close(),conn.close()
trim()是用来去首尾空格的。