Example usage for org.springframework.jdbc.support.rowset SqlRowSet getDouble

List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet getDouble

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.rowset SqlRowSet getDouble.

Prototype

double getDouble(String columnLabel) throws InvalidResultSetAccessException;

Source Link

Document

Retrieve the value of the indicated column in the current row as a Double object.

Usage

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String sellStorageProduct(HttpServletRequest req) {
    String val = "0", idInc, sqls[];
    double remain, size, offer, basePrice, price, lowest, highest;
    ArrayList<String> sqlL = new ArrayList<String>();
    SqlRowSet srs1, srs2;

    //0 = internal error
    //1 = CBM yg ditawarkan lebih besar dari yg dimiliki
    //2 = harga melampaui 25% lebih murah dari harga jual yang disarankan
    //3 = harga melampaui 25% lebih mahal dari harga jual yang disarankan

    srs1 = db.getJdbc().queryForRowSet("select price,size from storage_product,desc_product where id='"
            + req.getParameter("productId") + "' and storage_product.[desc]=desc_product.id");
    if (srs1.next()) {
        size = srs1.getDouble("size");
        basePrice = srs1.getDouble("price");
    } else//from  w  w w  .jav  a 2 s .c  om
        return "0";

    srs1 = db.getJdbc().queryForRowSet(
            "select size from market_product where storage_product_id='" + req.getParameter("productId") + "'");
    if (srs1.next())
        size -= srs1.getDouble("size");

    offer = Double.parseDouble(req.getParameter("offer"));
    price = Double.parseDouble(req.getParameter("price"));
    lowest = basePrice - (basePrice * 0.25);
    highest = basePrice + (basePrice * 0.25);

    if (size < offer)
        return "1";

    if (price < lowest)
        return "2";

    if (price > highest)
        return "3";

    srs1 = db.getJdbc()
            .queryForRowSet("select id,size from market_product where storage_product_id='"
                    + req.getParameter("productId") + "' and [zone]='" + req.getParameter("zone")
                    + "' and price='" + req.getParameter("price") + "'");
    if (srs1.next())
        sqlL.add("update market_product set size='" + (srs1.getDouble("size") + offer) + "' where id='"
                + srs1.getString("id") + "'");
    else {
        idInc = getUniqueIncrementIdNew("market_product");
        sqlL.add("insert into market_product values ('" + KEY_MARKET_PRODUCT + idInc + "','"
                + req.getParameter("productId") + "','','" + req.getParameter("zone") + "','"
                + req.getParameter("price") + "','" + offer + "')");
    }

    sqls = new String[sqlL.size()];
    sqlL.toArray(sqls);
    db.getJdbc().batchUpdate(sqls);

    val = "Ok";

    //      srs1 = db.getJdbc().queryForRowSet("select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage='"+req.getParameter("storage")+"' and desc_product.id=storage_product.desc and product=name");
    //      ArrayList<StorageProduct> products = new ArrayList<StorageProduct>();
    //      while(srs1.next()){
    //         remain = srs1.getDouble("size");
    //         srs2 = db.getJdbc().queryForRowSet("select size from market_product where storage_product_id='"+srs1.getString("id")+"'");
    //         while(srs2.next()){
    //            remain -= srs2.getDouble("size");
    //         }
    //         if(remain > 0)
    //            products.add(new StorageProduct(srs1.getString("id"), srs1.getString("product"), srs1.getInt("quality"), new BigDecimal(Double.valueOf(remain)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(), srs1.getString("draw")));
    //      }

    srs1 = db.getJdbc().queryForRowSet(
            "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage='"
                    + req.getParameter("storage")
                    + "' 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()) {
        remain = 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()) {
            remain -= 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 (remain > 0)
            storageProducts
                    .add(new StorageProduct(srs1.getString("id"), srs1.getString("product"),
                            srs1.getInt("quality"), new BigDecimal(Double.valueOf(remain))
                                    .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(),
                            srs1.getString("draw")));
    }

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(storageProducts));
    data.add(gson.toJson(marketProducts));
    val = gson.toJson(data);

    sqlL = null;
    storageProducts = null;
    marketProducts = null;
    sqls = null;
    srs1 = null;
    srs2 = null;
    idInc = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String refreshClientData(HttpServletRequest req) {
    SqlRowSet srs;
    //      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";

    srs = db.getJdbc().queryForRowSet("select sector,cost from user_sector_blueprint,info_sector where [user]='"
            + req.getParameter("user") + "' and sector=name");
    HashMap<String, Double> sectorCosts = new HashMap<String, Double>();
    while (srs.next()) {
        sectorCosts.put(srs.getString("sector"), srs.getDouble("cost"));
    }/*  w w w  . j  ava 2  s  . co m*/

    String val = "0";
    srs = db.getJdbc().queryForRowSet("select money,rep,cost from [user],info_zone where name='"
            + req.getParameter("user") + "' and id=[zone]");
    User user;
    if (srs.next())
        user = new User("", "", "", "", srs.getDouble("money"), srs.getDouble("cost"), srs.getLong("rep"), "",
                0, new HashMap<String, String>(), new HashMap<String, String>(), new HashMap<String, String>(),
                sectorCosts, new ArrayList<Installment>());
    else
        return "0";

    val = gson.toJson(user);

    srs = null;
    sectorCosts = null;
    user = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String loadInstallmentDetails(HttpServletRequest req) {
    String val = "0";
    ArrayList<InstallmentEmployee> employees = new ArrayList<InstallmentEmployee>();
    ArrayList<InstallmentEquipment> equipments = new ArrayList<InstallmentEquipment>();
    ArrayList<String> data = new ArrayList<String>();

    SqlRowSet srs1 = db.getJdbc().queryForRowSet(
            "select installment_employee.id,employee,quality,operational,draw from installment_employee,list_employee,desc_employee,info_employee where installment='"
                    + req.getParameter("id")
                    + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id and name=employee"),
            srs2;/*from  ww w . ja v  a 2s.c  o m*/

    while (srs1.next()) {
        employees.add(new InstallmentEmployee(srs1.getString("id"), srs1.getString("employee"),
                srs1.getInt("quality"), srs1.getDouble("operational"), srs1.getString("draw")));
    }

    srs1 = db.getJdbc().queryForRowSet(
            "select installment_equipment.id,equipment,quality,durability,size,operational,draw from installment_equipment,desc_equipment,list_equipment,info_equipment where installment='"
                    + req.getParameter("id")
                    + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment");
    while (srs1.next()) {
        equipments.add(new InstallmentEquipment(srs1.getString("id"), srs1.getString("equipment"),
                srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"),
                srs1.getDouble("operational"), srs1.getString("draw")));
    }

    ArrayList<String> installmentIOdata = calculateInstallmentAndIOByIdInstallment(req.getParameter("id"));
    data.add(installmentIOdata.get(0));
    data.add(installmentIOdata.get(1));
    data.add(installmentIOdata.get(2));
    data.add(installmentIOdata.get(3));
    data.add(installmentIOdata.get(4));
    data.add(installmentIOdata.get(5));
    data.add(installmentIOdata.get(6));
    data.add(installmentIOdata.get(7));
    data.add(gson.toJson(equipments));
    data.add(gson.toJson(employees));

    if (installmentIOdata.get(0).equals("Petrol Power Plant")) {
        srs1 = db.getJdbc().queryForRowSet(
                "select subscription,tariff from installment where id='" + req.getParameter("id") + "'");
        double tariff, subscription;
        if (srs1.next()) {
            subscription = srs1.getDouble("subscription");
            tariff = srs1.getDouble("tariff");
        } else
            return "0";

        srs1 = db.getJdbc()
                .queryForRowSet("select id,type,[user],planned_supply from installment where supply='"
                        + req.getParameter("id") + "'");
        ArrayList<String> types = new ArrayList<String>(), users = new ArrayList<String>(),
                idSupplies = new ArrayList<String>();
        ArrayList<Double> supplies = new ArrayList<Double>();
        while (srs1.next()) {
            idSupplies.add(srs1.getString("id"));
            types.add(srs1.getString("type"));
            users.add(srs1.getString("user"));
            supplies.add(srs1.getDouble("planned_supply"));
        }

        data.add(gson.toJson(subscription));
        data.add(gson.toJson(tariff));
        data.add(gson.toJson(types));
        data.add(gson.toJson(users));
        data.add(gson.toJson(supplies));
        data.add(gson.toJson(idSupplies));

        val = gson.toJson(data);

        types = null;
        users = null;
        supplies = null;
        idSupplies = null;

    } else {
        srs1 = db.getJdbc().queryForRowSet(
                "select supply,planned_supply from installment where id='" + req.getParameter("id") + "'");
        ArrayList<String> idSupplies = new ArrayList<String>(), users = new ArrayList<String>(), tmpSupplies;
        ArrayList<Double> subscriptions = new ArrayList<Double>(), tariffs = new ArrayList<Double>(),
                availables = new ArrayList<Double>();
        JsonParser parser = new JsonParser();
        JsonArray array1;
        int tmp;
        double available, currentKwh;
        String currentSupply;

        if (srs1.next()) {
            currentKwh = srs1.getDouble("planned_supply");
            currentSupply = srs1.getString("supply");
        } else
            return "0";

        srs1 = db.getJdbc().queryForRowSet(
                "select id,[user],subscription,tariff from installment where type='Petrol Power Plant'");
        while (srs1.next()) {
            tmp = 0;
            tmpSupplies = calculateInstallmentAndIOByIdInstallment(srs1.getString("id"));
            array1 = parser.parse(tmpSupplies.get(5)).getAsJsonArray();
            for (int i = 0; i < array1.size(); i++) {
                if ((new Gson().fromJson(array1.get(i), String.class)).equals("Energy")) {
                    tmp = i;
                    break;
                }
            }
            array1 = parser.parse(tmpSupplies.get(6)).getAsJsonArray();
            available = new Gson().fromJson(array1.get(tmp), Double.class);
            srs2 = db.getJdbc().queryForRowSet(
                    "select planned_supply from installment where supply='" + srs1.getString("id") + "'");
            while (srs2.next())
                available -= srs2.getDouble("planned_supply");

            idSupplies.add(srs1.getString("id"));
            users.add(srs1.getString("user"));
            subscriptions.add(srs1.getDouble("subscription"));
            tariffs.add(srs1.getDouble("tariff"));
            availables.add(new BigDecimal(Double.valueOf(available)).setScale(2, BigDecimal.ROUND_HALF_EVEN)
                    .doubleValue());
            tmpSupplies = null;
        }

        data.add(gson.toJson(idSupplies));
        data.add(gson.toJson(users));
        data.add(gson.toJson(subscriptions));
        data.add(gson.toJson(tariffs));
        data.add(gson.toJson(availables));
        data.add(gson.toJson(currentKwh));
        data.add(gson.toJson(currentSupply));

        val = gson.toJson(data);

        idSupplies = null;
        users = null;
        tariffs = null;
        availables = null;
        currentSupply = null;
    }

    installmentIOdata = null;
    employees = null;
    equipments = null;
    data = null;
    srs1 = null;
    srs2 = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String attachEquipmentToInstallment(HttpServletRequest req) {
    String val = "0", sqls[];
    ArrayList<String> sqlL = new ArrayList<String>();

    sqlL.add("insert into installment_equipment values ('" + req.getParameter("idEquipment") + "','"
            + req.getParameter("idInstallment") + "')");
    sqlL.add("delete from storage_equipment where id='" + req.getParameter("idEquipment") + "'");

    sqls = new String[sqlL.size()];
    sqlL.toArray(sqls);//from   w  w w . ja  v  a2 s.  co  m
    db.getJdbc().batchUpdate(sqls);

    SqlRowSet srs1, srs2;

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

    Installment installment = getSingleUserInstallments(req.getParameter("idInstallment"));

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(equipments));
    data.add(gson.toJson(installment));

    val = gson.toJson(data);

    sqlL = null;
    equipments = null;
    srs1 = null;
    srs2 = null;
    sqls = null;
    installment = null;
    data = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String loadBankData(HttpServletRequest req) {
    String val = "";

    SqlRowSet srs = db.getJdbc()
            .queryForRowSet("select id from req_borrow_bank where [user]='" + req.getParameter("user") + "'");
    if (srs.next())
        return "1";

    srs = db.getJdbc()// w ww .  j av a2  s. c  o  m
            .queryForRowSet("select id from borrow_bank where [user]='" + req.getParameter("user") + "'");
    if (srs.next())
        return "2";

    ArrayList<String> sectorList = new ArrayList<String>(), data = new ArrayList<String>();
    ArrayList<Double> priceList = new ArrayList<Double>();
    ArrayList<BusinessSectorInfo> bsiList = new ArrayList<BusinessSectorInfo>();
    ArrayList<IndustrialEquipmentInfo> ie;
    ArrayList<EmployeeInfo> e;
    ArrayList<InputInfo> i;
    ArrayList<OutputInfo> o;
    double tmpd1, tmpd2;

    srs = db.getJdbc().queryForRowSet("select name, cost from info_sector");
    while (srs.next()) {
        sectorList.add(srs.getString("name"));
        priceList.add(srs.getDouble("cost"));
    }

    srs = db.getJdbc().queryForRowSet(
            "select cost from info_zone where id=(select [zone] from businessgame.dbo.[user] where name='"
                    + req.getParameter("user") + "')");
    if (srs.next())
        tmpd1 = srs.getDouble("cost");
    else
        return "0";

    srs = db.getJdbc().queryForRowSet("select [value] from info_values where name='cost_storage'");
    if (srs.next())
        tmpd2 = Double.parseDouble(srs.getString("value"));
    else
        return "0";

    for (String sector : sectorList) {
        srs = db.getJdbc().queryForRowSet(
                "select equipment_type,items,base_price,base_operational from info_sector_equipment,info_equipment where equipment_type=info_equipment.name and info_sector_equipment.sector='"
                        + sector + "'");

        ie = new ArrayList<IndustrialEquipmentInfo>();
        while (srs.next()) {
            ie.add(new IndustrialEquipmentInfo(srs.getString("equipment_type"), srs.getInt("items"),
                    srs.getDouble("base_price"), srs.getDouble("base_operational")));
        }

        srs = db.getJdbc().queryForRowSet(
                "select employee_type,items,base_price,base_operational from info_sector_employee,info_employee where employee_type=info_employee.name and info_sector_employee.sector='"
                        + sector + "'");
        e = new ArrayList<EmployeeInfo>();
        while (srs.next()) {
            e.add(new EmployeeInfo(srs.getString("employee_type"), srs.getInt("items"),
                    srs.getDouble("base_price"), srs.getDouble("base_operational")));
        }

        srs = db.getJdbc().queryForRowSet(
                "select input_type,base_price,size from info_sector_input,info_product where input_type=info_product.name and info_sector_input.sector='"
                        + sector + "'");
        i = new ArrayList<InputInfo>();
        while (srs.next()) {
            i.add(new InputInfo(srs.getString("input_type"), srs.getDouble("size"),
                    srs.getDouble("base_price")));
        }

        srs = db.getJdbc().queryForRowSet(
                "select output_type,base_price,size from info_sector_output,info_product where output_type=info_product.name and info_sector_output.sector='"
                        + sector + "'");
        o = new ArrayList<OutputInfo>();
        while (srs.next()) {
            o.add(new OutputInfo(srs.getString("output_type"), srs.getDouble("size"),
                    srs.getDouble("base_price")));
        }

        bsiList.add(new BusinessSectorInfo(ie, e, i, o));
        ie = null;
        e = null;
        i = null;
        o = null;
    }

    data.add(gson.toJson(sectorList));
    data.add(gson.toJson(priceList));
    data.add(gson.toJson(tmpd1));
    data.add(gson.toJson(tmpd2));
    data.add(gson.toJson(bsiList));

    val = gson.toJson(data);

    sectorList = null;
    priceList = null;
    bsiList = null;
    data = null;
    srs = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String cancelOfferProduct(HttpServletRequest req) {
    String val = "";
    double remain;

    db.getJdbc().execute("delete from market_product where id='" + req.getParameter("id") + "'");

    SqlRowSet srs1 = db.getJdbc().queryForRowSet(
            "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage=(select id from storage where [user]='"
                    + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone")
                    + "') and desc_product.id=storage_product.[desc] and product=name"),
            srs2;//from w  w  w .  j  av  a 2  s.  c o  m

    srs1 = db.getJdbc().queryForRowSet(
            "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage=(select id from storage where [user]='"
                    + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone")
                    + "') 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()) {
        remain = 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()) {
            remain -= 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 (remain > 0)
            storageProducts
                    .add(new StorageProduct(srs1.getString("id"), srs1.getString("product"),
                            srs1.getInt("quality"), new BigDecimal(Double.valueOf(remain))
                                    .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(),
                            srs1.getString("draw")));
    }

    //      ArrayList<StorageProduct> products = new ArrayList<StorageProduct>();
    //      while(srs1.next()){
    //         remain = srs1.getDouble("size");
    //         srs2 = db.getJdbc().queryForRowSet("select size from market_product where storage_product_id='"+srs1.getString("id")+"'");
    //         while(srs2.next()){
    //            remain -= srs2.getDouble("size");
    //         }
    //         if(remain > 0)
    //            products.add(new StorageProduct(srs1.getString("id"), srs1.getString("product"), srs1.getInt("quality"), new BigDecimal(Double.valueOf(remain)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(), srs2.getString("draw")));
    //      }
    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(storageProducts));
    data.add(gson.toJson(marketProducts));
    val = gson.toJson(data);

    data = null;
    marketProducts = null;
    storageProducts = null;
    srs1 = null;
    srs2 = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String registerUser(HttpServletRequest req) {
    String val = "", sqls[], idInc;
    SqlRowSet srs = db.getJdbc().queryForRowSet(
            "select name from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'");
    ArrayList<String> sqlL = new ArrayList<String>();

    if (srs.next())
        return "1";
    sqlL.add("insert into businessgame.dbo.[user] values ('" + req.getParameter("user") + "','"
            + req.getParameter("pass") + "','" + req.getParameter("email") + "','" + req.getParameter("dob")
            + "','This is me',0.00,0,'" + req.getParameter("zone") + "',1)");

    idInc = getUniqueIncrementIdNew("user_market_license");

    HashMap<String, String> marketLicense = new HashMap<String, String>();
    sqlL.add("insert into businessgame.dbo.[user_market_license] values ('" + KEY_USER_MARKET_LICENSE + idInc
            + "','" + req.getParameter("user") + "','" + req.getParameter("zone") + "')");
    marketLicense.put(req.getParameter("zone"), KEY_USER_MARKET_LICENSE + idInc);

    srs = db.getJdbc().queryForRowSet("select cost from info_zone where id='" + req.getParameter("zone") + "'");
    double propCost;
    if (srs.next()) {
        propCost = srs.getDouble("cost");
    } else/*w  w w . ja  v a  2s  .c  om*/
        return "0";

    sqls = new String[sqlL.size()];
    sqlL.toArray(sqls);
    db.getJdbc().batchUpdate(sqls);

    User user = new User(req.getParameter("user"), req.getParameter("email"), req.getParameter("dob"),
            "This is me", 0.00, propCost, 0, req.getParameter("zone"), 1, new HashMap<String, String>(),
            marketLicense, new HashMap<String, String>(), new HashMap<String, Double>(),
            new ArrayList<Installment>());

    val = gson.toJson(user);

    sqls = null;
    sqlL = null;
    srs = null;
    idInc = null;
    user = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String loadMarketContent(HttpServletRequest req) {
    String val = "0";
    SqlRowSet srs;

    //      srs = db.getJdbc().queryForRowSet("select market_product.id,storage.[user],product,market_product.price,quality,market_product.size,draw from market_product,storage_product,desc_product,storage,info_product where market_product.[zone]='"+req.getParameter("zone")+"' and storage_product.id=storage_product_id and desc_product.id=storage_product.[desc] and storage.id=storage_product.storage and product=name union select market_product.id,'',product,market_product.price,quality,market_product.size,draw from market_product,desc_product,info_product where market_product.[zone]='"+req.getParameter("zone")+"' and desc_product.id=market_product.[desc] and product=name");
    srs = db.getJdbc().queryForRowSet(//w  ww .jav a 2 s.  com
            "select market_product.id,storage.[user],product,market_product.price,quality,market_product.size,draw from market_product,storage_product,desc_product,storage,info_product where market_product.[zone]='"
                    + req.getParameter("zone")
                    + "' and storage_product.id=storage_product_id and desc_product.id=storage_product.[desc] and storage.id=storage_product.storage and product=name");
    ArrayList<MarketProduct> products = new ArrayList<MarketProduct>();
    while (srs.next()) {
        products.add(new MarketProduct(srs.getString("id"), srs.getString("user"), srs.getString("product"),
                srs.getDouble("price"), srs.getInt("quality"), srs.getDouble("size"), srs.getString("draw")));
    }

    //      srs = db.getJdbc().queryForRowSet("select market_equipment.id,storage.[user],equipment,market_equipment.price,quality,durability,size,operational,draw from market_equipment,storage_equipment,desc_equipment,list_equipment,storage,info_equipment where market_equipment.[zone]='"+req.getParameter("zone")+"' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and storage.id=storage_equipment.storage and equipment=name union select market_equipment.id,'',equipment,market_equipment.price,quality,durability,size,operational,draw from market_equipment,desc_equipment,list_equipment,info_equipment where market_equipment.[zone]='"+req.getParameter("zone")+"' and list_equipment.id=market_equipment.[desc] and list_equipment.[desc]=desc_equipment.id and equipment=name");
    srs = db.getJdbc().queryForRowSet(
            "select market_equipment.id,storage.[user],equipment,market_equipment.price,quality,durability,size,operational,draw from market_equipment,storage_equipment,desc_equipment,list_equipment,storage,info_equipment where market_equipment.[zone]='"
                    + req.getParameter("zone")
                    + "' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and storage.id=storage_equipment.storage and equipment=name");
    ArrayList<MarketEquipment> equipments = new ArrayList<MarketEquipment>();
    while (srs.next()) {
        equipments
                .add(new MarketEquipment(srs.getString("id"), srs.getString("user"), srs.getString("equipment"),
                        srs.getDouble("price"), srs.getInt("quality"), srs.getDouble("durability"),
                        srs.getDouble("size"), srs.getDouble("operational"), srs.getString("draw")));
    }

    srs = db.getJdbc().queryForRowSet(
            "select market_employee.id,employee,market_employee.price,quality,operational,draw from market_employee,desc_employee,list_employee,info_employee where [zone]='"
                    + req.getParameter("zone")
                    + "' and list_employee.id=market_employee.[desc] and desc_employee.id=list_employee.[desc] and name=employee");
    ArrayList<MarketEmployee> employees = new ArrayList<MarketEmployee>();
    while (srs.next()) {
        employees.add(new MarketEmployee(srs.getString("id"), srs.getString("employee"), srs.getDouble("price"),
                srs.getInt("quality"), srs.getDouble("operational"), srs.getString("draw")));
    }

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(products));
    data.add(gson.toJson(equipments));
    data.add(gson.toJson(employees));

    val = gson.toJson(data);

    products = null;
    equipments = null;
    employees = null;
    data = null;
    srs = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String detachEquipment(HttpServletRequest req) {
    String val = "0", idStorage, sqls[];
    ArrayList<String> sqlL = new ArrayList<String>();
    SqlRowSet srs;

    //0 = internal error
    //1 = user belum memiliki storage

    srs = db.getJdbc()//from  w  w  w  . j av  a2 s.  c o  m
            .queryForRowSet("select id from storage where [user]='" + req.getParameter("user")
                    + "' and [zone]=(select [zone] from businessgame.dbo.[user] where name='"
                    + req.getParameter("user") + "')");
    if (srs.next())
        idStorage = srs.getString("id");
    else
        return "1";

    sqlL.add("delete from installment_equipment where id='" + req.getParameter("idEquipment") + "'");

    sqlL.add("insert into storage_equipment values ('" + req.getParameter("idEquipment") + "','" + idStorage
            + "')");

    sqls = new String[sqlL.size()];
    sqlL.toArray(sqls);
    db.getJdbc().batchUpdate(sqls);

    srs = db.getJdbc().queryForRowSet(
            "select installment_equipment.id,equipment,quality,durability,size,operational,draw from installment_equipment,desc_equipment,list_equipment,info_equipment where installment='"
                    + req.getParameter("id")
                    + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment");
    ArrayList<InstallmentEquipment> equipments = new ArrayList<InstallmentEquipment>();
    while (srs.next()) {
        equipments.add(new InstallmentEquipment(srs.getString("id"), srs.getString("equipment"),
                srs.getInt("quality"), srs.getDouble("durability"), srs.getDouble("size"),
                srs.getDouble("operational"), srs.getString("draw")));
    }

    Installment installment = getSingleUserInstallments(req.getParameter("id"));

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(equipments));
    data.add(gson.toJson(installment));

    val = gson.toJson(data);

    equipments = null;
    installment = null;
    data = null;
    sqlL = null;
    sqls = null;
    idStorage = null;
    srs = null;

    gc();

    return val;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String cancelOfferEquipment(HttpServletRequest req) {
    String val = "";
    db.getJdbc().execute("delete from market_equipment where id='" + req.getParameter("id") + "'");

    SqlRowSet srs1, srs2;

    srs1 = db.getJdbc().queryForRowSet(//w  ww . ja v a2 s  .  com
            "select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage=(select id from storage where [user]='"
                    + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone")
                    + "') 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);

    data = null;
    marketEquipments = null;
    storageEquipments = null;
    srs1 = null;
    srs2 = null;

    gc();

    return val;
}