user2379250
user2379250

Reputation:

Inserting data from html to database, query error

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.

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

Upvotes: 1

Views: 243

Answers (3)

Tofiq
Tofiq

Reputation: 3001

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

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')";

Upvotes: 2

dratewka
dratewka

Reputation: 2114

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)

Upvotes: 0

MBulava
MBulava

Reputation: 521

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

Upvotes: 0

Related Questions