Jessie Den Ridder Jessie Den Ridder - 5 months ago 8
MySQL Question

How to put a sum in a String and print it

I'm currntly working on a reciept of an Java application and I can't seem to get the sum on the screen. When is use the following query I get the sum in PHPMyAdmin but can't seem to find it in Java. I just can't print it because Java tells me all the collum names I try are wrong. Does annyone know how to fix this?

If you want more code than this I can provide that but I'm kinda sure there is something faulty in the query and Java can't read it out. Help will be appreciated.

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

Answer

Put your sum as a val and get this value like this

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

and when you want to get the result

int som = getInt("val");
Comments