Reputation: 1
For some reason when my java code attempts to execute a query that is using a variable I receive a syntax error.
String query = "SELECT userName, email, address FROM users,requests"
+ "WHERE requestingUser = userID AND rideID = ?";
ps = connection.prepareStatement(query);
ps.setInt(1, rideID);
results = ps.executeQuery()
This code produces the following MySQL error:
"You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '= userID AND rideID = 34' at
line 1"
I have tried this both with and without using PreparedStatments, and I only receive an error for those queries for which I pass in a variable. Simple queries like "SELECT field FROM table" work fine. I feel like I am going insane, I appreciate any help I can get.
Upvotes: 0
Views: 169