如何在字符串中加一个总和并打印出来

时间:2016-06-16 18:09:37

标签: java mysql

我目前正在处理Java应用程序的收据,但我似乎无法在屏幕上获得总和。何时使用以下查询我在PHPMyAdmin中得到总和,但似乎无法在Java中找到它。我只是无法打印它,因为Java告诉我我尝试的所有列名都是错误的。有谁知道如何解决这个问题?

如果你想要更多的代码,我可以提供,但我确定查询中有一些错误,Java无法读出来。帮助将不胜感激。

String sql = "SELECT sum((`barorder_drink`.`quantity` * `drink`.`price`)) + sum((`kitchenorder_dish`.`quantity` * `dish`.`price`))"
        + "FROM `barorder`, `barorder_drink`, `drink`, `kitchenorder`, `kitchenorder_dish`, `dish`, `restaurantorder`"
        + "WHERE `barorder`.`restaurantOrderId` = `restaurantorder`.`id`"
        + "AND `kitchenorder`.`restaurantOrderId` = `restaurantorder`.`id`"
        + "AND `barorder_drink`.`barorderId` = `barorder`.`id`"
        + "AND `barorder_drink`.`drinkId` = `drink`.`id`"
        + "AND `kitchenorder_dish`.`kitchenOrderId` = `kitchenorder`.`id`"
        + "AND `kitchenorder_dish`.`dishId` = `dish`.`id`"
        + "AND `restaurantorder`.`id` = '" + ID + "' ;";

2 个答案:

答案 0 :(得分:2)

将你的总和作为一个val并得到这个值

String sql = "SELECT sum(myattributes) AS val";

当你想得到结果时

int som = getInt("val");

答案 1 :(得分:0)

也许当你这样做时))“ +“FROM ...

结果是:))FROM 它应该是))FROM