List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet getDouble
double getDouble(String columnLabel) throws InvalidResultSetAccessException;
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String checkUserStorage(HttpServletRequest req) { String val = "No", id = ""; boolean isAvailable; SqlRowSet srs1, srs2; double tmp = 0; ArrayList<String> data = new ArrayList<String>(); srs1 = db.getJdbc()//from w ww . ja v a2 s . co m .queryForRowSet("select [level] from storage where id='" + req.getParameter("storage") + "'"); isAvailable = srs1.next(); if (isAvailable) { id = req.getParameter("storage"); } else { srs1 = db.getJdbc().queryForRowSet("select id,[level] from storage where [user]='" + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone") + "'"); isAvailable = srs1.next(); if (isAvailable) id = srs1.getString("id"); } if (isAvailable) { int level = srs1.getInt("level") - 1; double capacity = 0, fill = 0, upgrade = 0, inc = 0; srs1 = db.getJdbc().queryForRowSet( "select [value] from info_values where name='storage' union select [value] from info_values where name='storage_inc' union select [value] from info_values where name='cost_storage_upgrade'"); if (srs1.next()) { capacity = Double.parseDouble(srs1.getString("value")); } else return "0"; if (srs1.next()) { capacity += level * Double.parseDouble(srs1.getString("value")); inc = Double.parseDouble(srs1.getString("value")); } else return "0"; if (srs1.next()) { upgrade = Double.parseDouble(srs1.getString("value")); } else return "0"; srs1 = db.getJdbc().queryForRowSet( "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage='" + id + "' and desc_product.id=storage_product.[desc] and product=name"); ArrayList<StorageProduct> storageProducts = new ArrayList<StorageProduct>(); ArrayList<MarketProduct> marketProducts = new ArrayList<MarketProduct>(); while (srs1.next()) { tmp = srs1.getDouble("size"); srs2 = db.getJdbc().queryForRowSet( "select market_product.id,product,market_product.price,quality,market_product.size,draw from market_product,desc_product,info_product,storage_product where storage_product_id='" + srs1.getString("id") + "' and storage_product_id=storage_product.id and desc_product.id=storage_product.[desc] and product=name"); while (srs2.next()) { tmp -= srs2.getDouble("size"); marketProducts.add(new MarketProduct(srs2.getString("id"), "", srs2.getString("product"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("size"), srs2.getString("draw"))); } if (tmp > 0) storageProducts.add(new StorageProduct(srs1.getString("id"), srs1.getString("product"), srs1.getInt("quality"), new BigDecimal(Double.valueOf(tmp)) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(), srs1.getString("draw"))); fill += srs1.getDouble("size"); } srs1 = db.getJdbc().queryForRowSet( "select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage='" + id + "' and storage_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment"); ArrayList<StorageEquipment> storageEquipments = new ArrayList<StorageEquipment>(); ArrayList<MarketEquipment> marketEquipments = new ArrayList<MarketEquipment>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select market_equipment.id,equipment,market_equipment.price,quality,durability,size,operational,draw from storage_equipment,market_equipment,desc_equipment,list_equipment,info_equipment where storage_equipment_id='" + srs1.getString("id") + "' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and equipment=name"); if (srs2.next()) { marketEquipments.add(new MarketEquipment(srs2.getString("id"), "", srs2.getString("equipment"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("durability"), srs2.getDouble("size"), srs2.getDouble("operational"), srs2.getString("draw"))); } else { storageEquipments.add(new StorageEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); } fill += srs1.getDouble("size"); } data.add(gson.toJson(isAvailable)); data.add(gson.toJson(capacity)); data.add(gson.toJson(fill)); data.add(gson.toJson(upgrade)); data.add(gson.toJson(inc)); data.add(gson.toJson(level + 1)); data.add(gson.toJson(storageProducts)); data.add(gson.toJson(storageEquipments)); data.add(gson.toJson(marketProducts)); data.add(gson.toJson(marketEquipments)); val = gson.toJson(data); storageProducts = null; storageEquipments = null; marketProducts = null; marketEquipments = null; } else { srs2 = db.getJdbc().queryForRowSet("select [value] from info_values where name='cost_storage'"); if (srs2.next()) { data.add(gson.toJson(isAvailable)); data.add(gson.toJson(Double.parseDouble(srs2.getString("value")))); val = gson.toJson(data); } else return "0"; } data = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String loadHeadquarterData(HttpServletRequest req) { String val = "0", contractType, user, zone; SqlRowSet srs1 = db.getJdbc().queryForRowSet("select name,[level] from info_sector"), srs2, srs3; ArrayList<String> sectors = new ArrayList<String>(); ArrayList<Integer> sectorsLvl = new ArrayList<Integer>(); while (srs1.next()) { sectors.add(srs1.getString("name")); sectorsLvl.add(srs1.getInt("level")); }/*from w w w . j a va2s .c o m*/ srs1 = db.getJdbc().queryForRowSet("select [value] from info_values where name='sector'"); double price; if (srs1.next()) { price = Double.parseDouble(srs1.getString("value")); } else return "0"; srs1 = db.getJdbc().queryForRowSet( "select user_contract.id,request_storage,supplier_storage,product,quality,size,user_contract.price,turn from user_contract,storage,desc_product where accept='1' and [user]='" + req.getParameter("user") + "' and product_desc=desc_product.id and (request_storage=storage.id or supplier_storage=storage.id)"); ArrayList<Contract> contracts = new ArrayList<Contract>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet("select [user],[zone] from storage where id='" + srs1.getString("request_storage") + "' union select [user],[zone] from storage where id='" + srs1.getString("supplier_storage") + "'"); if (srs2.next()) { if (srs2.getString("user").equals(req.getParameter("user"))) { contractType = "from"; srs2.next(); user = srs2.getString("user"); zone = srs2.getString("zone"); } else { contractType = "to"; user = srs2.getString("user"); zone = srs2.getString("zone"); } contracts .add(new Contract(srs1.getString("id"), user, zone, contractType, srs1.getString("product"), srs1.getInt("quality"), srs1.getDouble("size"), srs1.getDouble("price"))); } else return "0"; } srs1 = db.getJdbc().queryForRowSet( "select user_contract.id,request_storage,supplier_storage,product,quality,size,user_contract.price,turn from user_contract,storage,desc_product where accept='0' and [user]='" + req.getParameter("user") + "' and product_desc=desc_product.id and (request_storage=storage.id or supplier_storage=storage.id)"); ArrayList<Contract> pendingContracts = new ArrayList<Contract>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet("select [user],[zone] from storage where id='" + srs1.getString("request_storage") + "' union select [user],[zone] from storage where id='" + srs1.getString("supplier_storage") + "'"); if (srs2.next()) { if (srs2.getString("user").equals(req.getParameter("user"))) { contractType = "from"; srs2.next(); user = srs2.getString("user"); zone = srs2.getString("zone"); } else { contractType = "to"; user = srs2.getString("user"); zone = srs2.getString("zone"); } pendingContracts .add(new Contract(srs1.getString("id"), user, zone, contractType, srs1.getString("product"), srs1.getInt("quality"), srs1.getDouble("size"), srs1.getDouble("price"))); } else return "0"; } double sales = 0, raw = 0, electricity = 0, fixed = 0, wage = 0, operation = 0, transport = 0, retribution = 0, advertisement = 0, interest = 0, depreciation = 0, tax = 0; srs1 = db.getJdbc().queryForRowSet( "select type,total from user_finance where [user]='" + req.getParameter("user") + "'"); while (srs1.next()) { if (srs1.getString("type").equals("Sales")) sales = srs1.getDouble("total"); else if (srs1.getString("type").equals("Raw Material")) raw = srs1.getDouble("total"); else if (srs1.getString("type").equals("Electricity")) electricity = srs1.getDouble("total"); else if (srs1.getString("type").equals("Fixed")) fixed = srs1.getDouble("total"); else if (srs1.getString("type").equals("Wage")) wage = srs1.getDouble("total"); else if (srs1.getString("type").equals("Operation")) operation = srs1.getDouble("total"); else if (srs1.getString("type").equals("Transport")) transport = srs1.getDouble("total"); else if (srs1.getString("type").equals("Retribution")) retribution = srs1.getDouble("total"); else if (srs1.getString("type").equals("Advertisement")) advertisement = srs1.getDouble("total"); else if (srs1.getString("type").equals("Interest")) interest = srs1.getDouble("total"); else if (srs1.getString("type").equals("Depreciation")) depreciation = srs1.getDouble("total"); } srs1 = db.getJdbc().queryForRowSet("select [value] from info_values where name='tax'"); if (srs1.next()) tax = Double.parseDouble(srs1.getString("value")); else return "0"; double cash, rawOnStorage = 0, equipmentOnStorage = 0, loan = 0, storage = 0, equipment = 0, sector = 0, tmpd1, tmpd2, tmpd3; srs1 = db.getJdbc().queryForRowSet( "select money from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'"); if (srs1.next()) cash = srs1.getDouble("money"); else return "0"; srs1 = db.getJdbc().queryForRowSet( "select [value] from info_values where name='cost_storage' union select [value] from info_values where name='cost_storage_upgrade'"); if (srs1.next()) tmpd1 = Double.parseDouble(srs1.getString("value")); else return "0"; if (srs1.next()) tmpd2 = Double.parseDouble(srs1.getString("value")); else return "0"; srs1 = db.getJdbc() .queryForRowSet("select id,[level] from storage where [user]='" + req.getParameter("user") + "'"); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select size,avg_price from storage_product where storage='" + srs1.getString("id") + "'"); while (srs2.next()) { rawOnStorage += (srs2.getDouble("size") * srs2.getDouble("avg_price")); } srs2 = db.getJdbc().queryForRowSet( "select buy_price,durability from storage_equipment,list_equipment where storage='" + srs1.getString("id") + "' and storage_equipment.id=list_equipment.id"); while (srs2.next()) { equipmentOnStorage += srs2.getDouble("buy_price") * (srs2.getDouble("durability") / 100.00); } storage += tmpd1; for (int i = 1; i < srs1.getLong("level"); i++) { storage += tmpd2; } } srs1 = db.getJdbc() .queryForRowSet("select borrow from borrow_bank where [user]='" + req.getParameter("user") + "'"); while (srs1.next()) { loan += srs1.getDouble("borrow") * -1; } srs1 = db.getJdbc().queryForRowSet( "select installment.id,info_zone.cost,info_sector.cost from installment,info_zone,info_sector where [user]='" + req.getParameter("user") + "' and info_zone.id=[zone] and info_sector.name=type"); while (srs1.next()) { sector += srs1.getDouble(2) + srs1.getDouble(3); srs2 = db.getJdbc().queryForRowSet( "select buy_price,durability from installment_equipment,list_equipment where installment='" + srs1.getString(1) + "' and installment_equipment.id=list_equipment.id"); while (srs2.next()) { equipment += srs2.getDouble("buy_price") * (srs2.getDouble("durability") / 100.00); } } srs1 = db.getJdbc().queryForRowSet("select name from info_product"); ArrayList<String> products = new ArrayList<String>(); while (srs1.next()) { products.add(srs1.getString("name")); } srs1 = db.getJdbc().queryForRowSet("select id,advertise,price from desc_advertisement"); ArrayList<String> advertises = new ArrayList<String>(), idAds = new ArrayList<String>(); ArrayList<Double> prices = new ArrayList<Double>(); while (srs1.next()) { idAds.add(srs1.getString("id")); advertises.add(srs1.getString("advertise")); prices.add(srs1.getDouble("price")); } srs1 = db.getJdbc().queryForRowSet( "select name from businessgame.dbo.[user] where [zone]=(select [zone] from businessgame.dbo.[user] where name='" + req.getParameter("user") + "')"); ArrayList<String> players = new ArrayList<String>(); ArrayList<Double> assets = new ArrayList<Double>(); while (srs1.next()) { tmpd3 = 0; srs2 = db.getJdbc().queryForRowSet( "select money from businessgame.dbo.[user] where name='" + srs1.getString("name") + "'"); if (srs2.next()) tmpd3 += srs2.getDouble("money"); else return "0"; srs2 = db.getJdbc() .queryForRowSet("select id,[level] from storage where [user]='" + srs1.getString("name") + "'"); while (srs2.next()) { srs3 = db.getJdbc().queryForRowSet( "select size,avg_price from storage_product where storage='" + srs2.getString("id") + "'"); while (srs3.next()) { tmpd3 += (srs3.getDouble("size") * srs3.getDouble("avg_price")); } srs3 = db.getJdbc().queryForRowSet( "select buy_price,durability from storage_equipment,list_equipment where storage='" + srs2.getString("id") + "' and storage_equipment.id=list_equipment.id"); while (srs3.next()) { tmpd3 += srs3.getDouble("buy_price") * (srs3.getDouble("durability") / 100.00); } tmpd3 += tmpd1; for (int i = 1; i < srs2.getLong("level"); i++) { tmpd3 += tmpd2 * i; } } srs2 = db.getJdbc() .queryForRowSet("select borrow from borrow_bank where [user]='" + srs1.getString("name") + "'"); while (srs2.next()) { tmpd3 += srs2.getDouble("borrow") * -1; } srs2 = db.getJdbc().queryForRowSet( "select installment.id,info_zone.cost,info_sector.cost from installment,info_zone,info_sector where [user]='" + srs1.getString("name") + "' and info_zone.id=[zone] and info_sector.name=type"); while (srs2.next()) { tmpd3 += srs2.getDouble(2) + srs2.getDouble(3); srs3 = db.getJdbc().queryForRowSet( "select buy_price,durability from installment_equipment,list_equipment where installment='" + srs2.getString(1) + "' and installment_equipment.id=list_equipment.id"); while (srs3.next()) { tmpd3 += srs3.getDouble("buy_price") * (srs3.getDouble("durability") / 100.00); } } players.add(srs1.getString("name")); assets.add(tmpd3); } for (int i = 0; i < assets.size(); i++) { for (int j = i + 1; j < assets.size(); j++) { if (assets.get(i) < assets.get(j)) { user = players.get(i); tmpd3 = assets.get(i); players.set(i, players.get(j)); assets.set(i, assets.get(j)); players.set(j, user); assets.set(j, tmpd3); } } } ArrayList<String> data = new ArrayList<String>(); data.add(gson.toJson(sectors)); data.add(gson.toJson(sectorsLvl)); data.add(gson.toJson(price)); data.add(gson.toJson(contracts)); data.add(gson.toJson(pendingContracts)); data.add(gson.toJson(sales)); data.add(gson.toJson(raw)); data.add(gson.toJson(electricity)); data.add(gson.toJson(fixed)); data.add(gson.toJson(wage)); data.add(gson.toJson(operation)); data.add(gson.toJson(transport)); data.add(gson.toJson(retribution)); data.add(gson.toJson(advertisement)); data.add(gson.toJson(interest)); data.add(gson.toJson(depreciation)); data.add(gson.toJson(tax)); data.add(gson.toJson(cash)); data.add(gson.toJson(rawOnStorage)); data.add(gson.toJson(equipmentOnStorage)); data.add(gson.toJson(loan)); data.add(gson.toJson(storage)); data.add(gson.toJson(equipment)); data.add(gson.toJson(sector)); data.add(gson.toJson(products)); data.add(gson.toJson(idAds)); data.add(gson.toJson(advertises)); data.add(gson.toJson(prices)); data.add(gson.toJson(players)); val = gson.toJson(data); sectors = null; sectorsLvl = null; contracts = null; pendingContracts = null; data = null; contractType = null; user = null; products = null; advertises = null; prices = null; players = null; assets = null; zone = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String loginUser(HttpServletRequest req) { String val = "Ok"; SqlRowSet srs1 = db.getJdbc().queryForRowSet("select [value] from info_values where name='ver'"), srs2; if (srs1.next()) { if (!srs1.getString("value").equals(req.getParameter("ver"))) return "2"; } else/*from w ww . ja v a2 s. co m*/ return "0"; srs1 = db.getJdbc().queryForRowSet( "select * from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'"); System.out.println("Ver : " + req.getParameter("ver")); User userAcc; if (srs1.next()) { if (req.getParameter("pass").equals(srs1.getString("pass"))) { HashMap<String, String> storages = new HashMap<String, String>(), marketLicenses = new HashMap<String, String>(), sectorBlueprints = new HashMap<String, String>(); HashMap<String, Double> sectorCost = new HashMap<String, Double>(); ArrayList<Installment> installments = getUserInstallments(req.getParameter("user")); srs2 = db.getJdbc() .queryForRowSet("select cost from info_zone where id='" + srs1.getString("zone") + "'"); double propCost; if (srs2.next()) { propCost = srs2.getDouble("cost"); } else return "0"; srs2 = db.getJdbc().queryForRowSet( "select id,[zone] from storage where [user]='" + req.getParameter("user") + "'"); while (srs2.next()) { storages.put(srs2.getString("zone"), srs2.getString("id")); } srs2 = db.getJdbc().queryForRowSet("select id,[zone] from user_market_license where [user]='" + req.getParameter("user") + "'"); while (srs2.next()) { marketLicenses.put(srs2.getString("zone"), srs2.getString("id")); } System.out.println(marketLicenses); srs2 = db.getJdbc().queryForRowSet( "select id,sector,cost from user_sector_blueprint,info_sector where [user]='" + req.getParameter("user") + "' and sector=name"); while (srs2.next()) { sectorBlueprints.put(srs2.getString("sector"), srs2.getString("id")); sectorCost.put(srs2.getString("sector"), srs2.getDouble("cost")); } userAcc = new User(srs1.getString("name"), srs1.getString("email"), srs1.getString("dob"), srs1.getString("about"), srs1.getDouble("money"), propCost, srs1.getLong("rep"), srs1.getString("zone"), srs1.getInt("level"), storages, marketLicenses, sectorBlueprints, sectorCost, installments); val = gson.toJson(userAcc); storages = null; marketLicenses = null; sectorBlueprints = null; sectorCost = null; installments = null; } else val = "0"; } else val = "1"; userAcc = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String sellStorageEquipment(HttpServletRequest req) { String val = "0", idInc, sqls[]; ArrayList<String> sqlL = new ArrayList<String>(); SqlRowSet srs1, srs2; idInc = getUniqueIncrementIdNew("market_equipment"); sqlL.add("insert into market_equipment values ('" + KEY_MARKET_EQUIPMENT + idInc + "','" + req.getParameter("equipmentId") + "','" + req.getParameter("marketZone") + "'," + req.getParameter("price") + ")"); System.out.println("insert into market_equipment values ('" + KEY_MARKET_EQUIPMENT + idInc + "','" + req.getParameter("equipmentId") + "','" + req.getParameter("marketZone") + "'," + req.getParameter("price") + ")"); sqls = new String[sqlL.size()]; sqlL.toArray(sqls);//from ww w .ja v a2s . c om db.getJdbc().batchUpdate(sqls); // srs1 = db.getJdbc().queryForRowSet("select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage='"+req.getParameter("storage")+"' and storage_equipment.id=list_equipment.id and list_equipment.desc=desc_equipment.id and name=equipment"); // ArrayList<StorageEquipment> equipments = new ArrayList<StorageEquipment>(); // while(srs1.next()){ // srs2 = db.getJdbc().queryForRowSet("select id from market_equipment where storage_equipment_id='"+srs1.getString("id")+"'"); // if(!srs2.next()) // equipments.add(new StorageEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); // } srs1 = db.getJdbc().queryForRowSet( "select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage='" + req.getParameter("storage") + "' and storage_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment"); ArrayList<StorageEquipment> storageEquipments = new ArrayList<StorageEquipment>(); ArrayList<MarketEquipment> marketEquipments = new ArrayList<MarketEquipment>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select market_equipment.id,equipment,market_equipment.price,quality,durability,size,operational,draw from storage_equipment,market_equipment,desc_equipment,list_equipment,info_equipment where storage_equipment_id='" + srs1.getString("id") + "' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and equipment=name"); if (srs2.next()) { marketEquipments.add(new MarketEquipment(srs2.getString("id"), "", srs2.getString("equipment"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("durability"), srs2.getDouble("size"), srs2.getDouble("operational"), srs2.getString("draw"))); } else { storageEquipments.add(new StorageEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); } } ArrayList<String> data = new ArrayList<String>(); data.add(gson.toJson(storageEquipments)); data.add(gson.toJson(marketEquipments)); val = gson.toJson(data); storageEquipments = null; marketEquipments = null; sqlL = null; sqls = null; srs1 = null; srs2 = null; idInc = null; gc(); return val; }