JSP向ACCESS插入记录的报SQL语法错误

<%@pagecontentType="textml;charset=GB2312"%><%@pageimport="java.util.*,java.sql.*"%><... <%@page contentType="text ml;charset=GB2312"%>
<%@page import="java.util.*,java.sql.*"%>
<%request.setCharacterEncoding("GB2312");%>

<%request.setCharacterEncoding("gb2312");%>

<HTML>
<HEAD>
<TITLE> </TITLE>

</HEAD>

<BODY><BR><BR><BR><BR><BR><BR>
<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //加载驱动程序

//catch(Exception e)

//System.out.println("驱动程序加载失败"+e);

//Connection conn=null;
//Statement stmt=null;
//ResultSet rs=null;

Connection conn = DriverManager.getConnection("jdbc:odbc:db1"); //建立数据库链接,library为数据源名称,这里应该填写你刚刚建立的数据源的名称
Statement stmt = conn.createStatement();//建立语句对象

String str1 = "'"+request.getParameter("txtnm")+"'";
String str2 = "'"+request.getParameter("txtpw")+"'";
String strupd = "insert into Text(Name,Password) values("+str1+","+str2+")";//正常的sql语言,可以自己编写
stmt.executeUpdate(strupd);//查询语言时这里要改为stmt.executeQuery

// rs = stmt.executeQuery(sql); //将查询结果放入数据集中

//rs.close();
//stmt.close();
//conn.close();

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

</BODY>
< ML>】

总报错
org.apache.jasper.JasperException: Exception in JSP: /zc.jsp:45

42: String str1 = "'"+request.getParameter("txtnm")+"'";
43: String str2 = "'"+request.getParameter("txtpw")+"'";
44: String strupd = "insert into Text(Name,Password) values("+str1+","+str2+")";//正常的sql语言,可以自己编写
45: stmt.executeUpdate(strupd);//查询语言时这里要改为stmt.executeQuery
46:
47: // rs = stmt.executeQuery(sql); //将查询结果放入数据集中
展开
 我来答
taotling
2009-06-14 · TA获得超过2000个赞
知道小有建树答主
回答量:412
采纳率:50%
帮助的人:380万
展开全部
使用了Access的关键字:
这种异常通常提示为:"XX语句有错误",比如:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] FROM 子句语法错误。
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句的语法错误。

Access数据库表名不能为text.
如果非要使用text这个关键字,则在拼写SQL语句时使用转义字符[],写为:
String strupd = "INSERT INTO [text](Name,Password) values("+str1+","+str2+")";

也就是将表名text用[]括起来.

Access保留字=====================================

-A
ABSOLUTE
ACTION
ADD
ADMINDB
ALL
ALLOCATE
ALPHANUMERIC
ALTER
AND
ANY
ARE
AS
ASC
ASSERTION
AT
AUTHORIZATION
AUTOINCREMENT
AVG
-B
BAND
BEGIN
BETWEEN
BINARY
BIT
BIT_LENGTH
BNOT
BOR
BOTH
BXOR
BY
BYTE
-C
CASCADE
CASCADED
CASE
CAST
CATALOG
CHAR
CHARACTER
CHAR_LENGTH
CHARACTER_LENGTH
CHECK
CLOSE
COALESCE
COLLATE
COLLATION
COLUMN
COMMIT
COMP
COMPRESSION
CONNECT
CONNECTION
CONSTRAINT
CONSTRAINTS
CONTAINER
CONTINUE
CONVERT
CORRESPONDING
COUNT
COUNTER
CREATE
CREATEDB
CROSS
CURRENCY
CURRENT
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
CURRENT_USER
CURSOR
-D
DATABASE
DATE
DATETIME
DAY
DEALLOCATE
DEC
DECIMAL
DECLARE
DEFAULT
DEFERRABLE
DEFERRED
DELETE
DESC
DESCRIBE
DESCRIPTOR
DIAGNOSTICS
DISALLOW
DISCONNECT
DISTINCT
DOMAIN
DOUBLE
DROP
-E
ELSE
END
END-EXEC
ESCAPE
EXCEPT
EXCEPTION
EXCLUSIVECONNECT
EXEC
EXECUTE
EXISTS
EXTERNAL
EXTRACT
-F
FALSE
FETCH
FIRST
FLOAT
FLOAT4
FLOAT8
FOR
FOREIGN
FOUND
FROM
FULL
-G
GENERAL
GET
GLOBAL
GO
GOTO
GRANT
GROUP
GUID
-H
HAVING
HOUR
-I
IDENTITY
IEEEDOUBLE
IEEESINGLE
IGNORE
IMAGE
IMMEDIATE
ININDEX
INDICATOR
INHERITABLE
INITIALLY
INNER
INPUT
INSENSITIVE
INSERT
INT
INTEGER
INTEGER1
INTEGER2
INTEGER4
INTERSECT
INTERVAL
INTO
IS
ISOLATION
-J
JOIN
-K
KEY
-L
LANGUAGE
LAST
LEADING
LEFT
LEVEL
LIKE
LOCAL
LOGICAL
LOGICAL1
LONG
LONGBINARY
LONGCHAR
LONGTEXT
LOWER
-M
MATCH
MAX
MEMO
MIN
MINUTE
MODULE
MONEY
MONTH
-N
NAMES
NATIONAL
NATURAL
NCHAR
NEXT
NO
NOT
NOTE
NULL
NULLIF
NUMBER
NUMERIC
-O
OBJECT
OCTET_LENGTH
OFOLEOBJECT
ONONLY
OPEN
OPTION
ORORDER
OUTER
OUTPUT
OVERLAPS
OWNERACCESS
-P
PAD
PARAMETERS
PARTIAL
PASSWORD
PERCENT
PIVOT
POSITION
PRECISION
PREPARE
PRESERVE
PRIMARY
PRIOR
PRIVILEGES
PROC
PROCEDURE
PUBLIC
-Q
-R
READ
REAL
REFERENCES
RELATIVE
RESTRICT
REVOKE
RIGHT
ROLLBACK
ROWS
-S
SCHEMA
SCROLL
SECOND
SECTION
SELECT
SELECTSCHEMA
SELECTSECURITY
SESSION
SESSION_USER
SET
SHORT
SINGLE
SIZE
SMALLINT
SOME
SPACE
SQL
SQLCODE
SQLERROR
SQLSTATE
STRING
SUBSTRING
SUM
SYSTEM_USER
-T
TABLE
TABLEID
TEMPORARY
TEXT
THEN
TIME
TIMESTAMP
TIMEZONE_HOUR
TIMEZONE_MINUTE
TO
TOP
TRAILING
TRANSACTION
TRANSFORM
TRANSLATE
TRANSLATION
TRIM
TRUE
-U
UNION
UNIQUE
UNIQUEIDENTIFIER
UNKNOWN
UPDATE
UPDATEIDENTITY
UPDATEOWNER
UPDATESECURITY
UPPER
USAGE
USER
USING
-V
VALUE
VALUES
VARBINARY
VARCHAR
VARYING
VIEW
-W
WHEN
WHENEVER
WHERE
WITH
WORK
WRITE
-X
-Y
YEAR
YESNO
-Z
ZONE
xv700
2009-06-14 · 超过33用户采纳过TA的回答
知道答主
回答量:277
采纳率:0%
帮助的人:115万
展开全部
方SQL试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式