0

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.

3
  • What is requestingUser? Commented Dec 4, 2013 at 2:09
  • 1
    Also, what is your JOIN criteria? Commented Dec 4, 2013 at 2:10
  • They are all integer values, so I don't see what the issue is. Commented Dec 4, 2013 at 2:12

1 Answer 1

3

You are missing a space between requests and WHERE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.