Reputation: 35
Im getting this :
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
For my code:
ResultSet results = state.executeQuery("SELECT * FROM User" + "WHERE user_name = '" +
txtUser.getText() + "'AND password = '" + txtPass.getText() + "'" );
I have already declared all of the variables, and i suspect the error has something to do with the structure however I am unsure. Thanks
Upvotes: 0
Views: 104
Reputation: 21184
If you pay close attention to your code on this line:
"SELECT * FROM User" + "WHERE user_name
You can see that this results in
SELECT * FROM UserWHERE user_name
You need to add in a space.
In addition you're opening yourself to SQL injection attacks by building your statement like this. You should really use a PreparedStatement
and use placeholder. You also won't need to build the statement by hand which would help you avoid this very issue.
Upvotes: 3