gpt4 book ai didi

java - 从html插入数据到数据库,查询错误

转载 作者:搜寻专家 更新时间:2023-10-30 23:14:18 24 4
gpt4 key购买 nike

从 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+'.

最佳答案

您的查询是错误的,如果所有 [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')";

关于java - 从html插入数据到数据库,查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16530693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com