开发者

Quick Java SQL problem

开发者 https://www.devze.com 2023-02-20 16:58 出处:网络
My code: String sql = \"SELECT Publisher.Name, Book.Title, ShopOrder.OrderDate, SUM(OrderLine.Quantity) AS No_Books, \"

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)


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";


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消