0

My code:

String sql = "SELECT Publisher.Name, Book.Title, ShopOrder.OrderDate, SUM(OrderLine.Quantity) AS No_Books, "
            + "SUM(OrderLine.UnitSellingPrice * Orderline.Quantity) AS Total_Price"
            + "FROM Publisher, Book, OrderLine, ShopOrder"
            + "WHERE OrderLine.BookID = Book.BookID AND ShopOrder.ShopOrderID = OrderLine.ShopOrderID AND Publisher.PublisherID = Book.PublisherID AND Publisher.PublisherID = " + id
            + "GROUP BY book.title, publisher.name, ShopOrder.OrderDate"
            + "ORDER BY ShopOrder.OrderDate, Book.Title";

Resulting error:

syntax error at or near "Publisher" at char position 166 (Just after the FROM clause)

3 Answers 3

5

Theres spaces missing

Your strings is ...S Total_PriceFROM Publisher, Book, OrderLine, ShopOrderWHERE O...

You should use:

String sql = "SELECT Publisher.Name, Book.Title, ShopOrder.OrderDate, SUM(OrderLine.Quantity) AS No_Books, "
        + " SUM(OrderLine.UnitSellingPrice * Orderline.Quantity) AS Total_Price"
        + " FROM Publisher, Book, OrderLine, ShopOrder"
        + " WHERE OrderLine.BookID = Book.BookID AND ShopOrder.ShopOrderID = OrderLine.ShopOrderID AND Publisher.PublisherID = Book.PublisherID AND Publisher.PublisherID = " + id
        + " GROUP BY book.title, publisher.name, ShopOrder.OrderDate"
            + " ORDER BY ShopOrder.OrderDate, Book.Title";
Sign up to request clarification or add additional context in comments.

Comments

0

When you concatenate those strings there is no space between Total_Price and FROM. And in other lines similarly. I always end and start a quoted SQL fragment with a space.

Comments

0

You need spaces either at the end of your lines or at the beginning. The resulting string would look like: ...AS Total_PriceFROM Publisher...

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.