将数据从html插入数据库,查询错误

时间:2022-01-12 04:30:24

Inserting data into database from a html page, I've successfully passed data to a jsp and then a java file, but I'm getting an error when inserting the data into the database.

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

This is the Query:

这是查询:

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

This is the error:

这是错误:

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

3 个解决方案

#1


2  

Your query is wrong, if all of this [HomeTeam,AwayTeam,HomeScore,AwayScore] are variables you should rewrite the query in this form:

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

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

but if those not variables you should write in this form:

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

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

#2


0  

You appear to be missing a single quote (') before your first value and then end of your last value.

您似乎在第一个值之前缺少单引号('),然后在最后一个值结束时丢失。

#3


0  

Looks like you're missing some quotes - try this:

看起来你错过了一些引用 - 试试这个:

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

(I assumed that HomeTeam, AwayTeam, HomeScore, AwayScore are variables)

(我认为HomeTeam,AwayTeam,HomeScore,AwayScore是变量)

#1


2  

Your query is wrong, if all of this [HomeTeam,AwayTeam,HomeScore,AwayScore] are variables you should rewrite the query in this form:

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

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

but if those not variables you should write in this form:

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

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

#2


0  

You appear to be missing a single quote (') before your first value and then end of your last value.

您似乎在第一个值之前缺少单引号('),然后在最后一个值结束时丢失。

#3


0  

Looks like you're missing some quotes - try this:

看起来你错过了一些引用 - 试试这个:

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

(I assumed that HomeTeam, AwayTeam, HomeScore, AwayScore are variables)

(我认为HomeTeam,AwayTeam,HomeScore,AwayScore是变量)