1

从 html 页面将数据插入数据库,我已经成功地将数据传递给 jsp,然后是 java 文件,但是在将数据插入数据库时​​出现错误。

这是查询:

String ResultQuery = "INSERT INTO Results (homeTeam, awayTeam, homeScore, awayScore)" +
    "VALUES (+HomeTeam+','+AwayTeam+','+HomeScore+','+AwayScore+)";

这是错误:

javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression '+HomeTeam+','+AwayTeam+','+HomeScore+','+AwayScore+'.
4

3 回答 3

2

您的查询是错误的,如果所有这些 [HomeTeam,AwayTeam,HomeScore,AwayScore] 都是变量,您应该以这种形式重写查询:

String ResultQuery = "INSERT INTO Results (homeTeam, awayTeam, homeScore, awayScore)" +
    "VALUES ('"+HomeTeam+"','"+AwayTeam+"','"+HomeScore+"','"+AwayScore+"')";

但如果那些不是变量,你应该用这种形式写:

String ResultQuery = "INSERT INTO Results (homeTeam, awayTeam, homeScore, awayScore)" +
    "VALUES ('HomeTeam','AwayTeam','HomeScore','AwayScore')";
于 2013-05-13T20:51:19.490 回答
0

您似乎在第一个值之前缺少一个单引号 ('),然后是最后一个值的结尾。

于 2013-05-13T20:40:59.903 回答
0

看起来你缺少一些引号 - 试试这个:

String ResultQuery = "INSERT INTO Results (homeTeam, awayTeam, homeScore, awayScore)" +
"VALUES ("+HomeTeam+"','"+AwayTeam+"','"+HomeScore+"','"+AwayScore+")";

(我假设HomeTeam, AwayTeam, HomeScore, AwayScore是变量)

于 2013-05-13T20:41:09.303 回答