0

I have an error

java.sql.SQLException: ORA-00933: SQL Command not properly ended

when I try to execute the following SQL Statement.

In this statement, it is supposed to display all the rental details and feedback for a particular customer when a customer name is searched. "query" refers to the user input when the user searches for a name (CustomerName) in the database.

 SELECT c.CustomerName, r.Rental_ID, r.Staff_ID, r.RentalDate, r.DueDate,
 r.Customer_ID, f.Description 
 FROM Rental r, Customer c, FeedBack f 
 WHERE f.Customer_ID = r.Customer_ID 
 AND c.Customer_ID = f.Customer_ID 
 ORDER BY DueDate 
 WHERE CustomerName like "+ query +";

What went wrong?

3
  • 1
    i hope you are not literally appending the user provided name into your query and are instead using PreparedStatements so as to avoid the glaring sql injection vulnerability. Commented Aug 13, 2016 at 3:48
  • @E.Wong your ORDER BY should come after the where clause change those places and check.. Commented Aug 13, 2016 at 4:12
  • Hmm, yea, I do have prepared statement, just not included in my question. Haha. xD Ah, I see, will do so and try it out. Thanks. :) Commented Aug 13, 2016 at 5:56

1 Answer 1

2

Cause you have the WHERE and ORDER BY clauses in wrong places; not only that you actually have two WHERE clause in your query. It should be only one. WHERE should come first and then order by. It should rather be

WHERE CustomerName like "+ query +"
ORDER BY DueDate;

Also as a side note,

  1. Consider using parameterized queries
  2. Modify your query to use ANSI standard JOIN syntax instead old style syntax.

Your query should look like

SELECT c.CustomerName, r.Rental_ID, 
r.Staff_ID, r.RentalDate, 
r.DueDate, r.Customer_ID, f.Description
FROM Rental r  
JOIN FeedBack f ON f.Customer_ID = r.Customer_ID
JOIN Customer c ON c.Customer_ID = f.Customer_ID
WHERE c.CustomerName like "+ query +"
ORDER BY r.DueDate;
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I see. My tutor taught me the old style syntax so I used that, but thanks for explaining. :)

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.