由于某些原因,当我的java代码尝试执行使用变量的查询时,我收到语法错误。
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()
此代码产生以下MySQL错误:
"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"
我在使用和不使用PreparedStatments的情况下尝试了这一点,我只收到了一个我传入变量的查询的错误。像“SELECT field FROM table”这样的简单查询工作正常。我觉得我疯了,我感谢任何帮助。
答案 0 :(得分:3)
您在请求和WHERE之间缺少空格