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

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

Introduction

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

Prototype

boolean next() throws InvalidResultSetAccessException;

Source Link

Document

Move the cursor to the next row.

Usage

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

public String queryTotalBundle(HttpServletRequest req) {
    String val = "";
    int quality;/* w  w  w  .ja va2s  .  c  om*/
    double total = 0;
    ArrayList<String> data = new ArrayList<String>();

    SqlRowSet srs1 = db.getJdbc()
            .queryForRowSet("select type from installment where id='" + req.getParameter("installment") + "'"),
            srs2;
    if (srs1.next()) {
        if (req.getParameter("quality") == null) {
            srs2 = db.getJdbc().queryForRowSet("select quality from info_quality where from_base='1'");
            if (srs2.next())
                quality = srs2.getInt("quality");
            else
                return "0";
        } else
            quality = Integer.parseInt(req.getParameter("quality"));

        srs2 = db.getJdbc()
                .queryForRowSet("select price,items from desc_equipment,info_sector_equipment where sector='"
                        + srs1.getString("type") + "' and quality='" + quality
                        + "' and desc_equipment.equipment=equipment_type");
        while (srs2.next()) {
            total += srs2.getDouble("price") * srs2.getInt("items");
        }

        srs2 = db.getJdbc()
                .queryForRowSet("select price,items from desc_employee,info_sector_employee where sector='"
                        + srs1.getString("type") + "' and quality='" + quality
                        + "' and desc_employee.employee=employee_type");
        while (srs2.next()) {
            total += srs2.getDouble("price") * srs2.getInt("items");
        }

        data.add(srs1.getString("type"));
        data.add(gson.toJson(total));

        val = gson.toJson(data);

    } else
        return "0";

    srs1 = null;
    srs2 = null;
    data = null;

    gc();

    return val;
}

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

public String advertiseProduct(HttpServletRequest req) {
    String val = "Ok", zone, idInc, sqls[];
    double money, price;
    ArrayList<String> sqlL = new ArrayList<String>();
    SqlRowSet srs = db.getJdbc().queryForRowSet(
            "select money,[zone] from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'");
    if (srs.next()) {
        zone = srs.getString("zone");
        money = srs.getDouble("money");
    } else//  ww w. ja v  a  2 s. c om
        return "0";

    srs = db.getJdbc()
            .queryForRowSet("select price from desc_advertisement where id='" + req.getParameter("ads") + "'");
    if (srs.next())
        price = srs.getDouble("price") * Double.parseDouble(req.getParameter("turn"));
    else
        return "0";

    if (money < price)
        return "1";

    money -= price;

    sqlL.add("update businessgame.dbo.[user] set money='" + money + "' where name='" + req.getParameter("user")
            + "'");

    //      srs = db.getJdbc().queryForRowSet("select total from user_finance where user='"+req.getParameter("user")+"' and type='Advertisement'");
    //      if(srs.next()){
    //         sqlL.add("update user_finance set total='"+(((srs.getDouble("total")*-1)+price)*-1)+"' where user='"+req.getParameter("user")+"' and type='Advertisement'");
    //      } else {
    //         idInc = getUniqueIncrementIdNew("user_finance");
    //         sqlL.add("insert into user_finance values ('"+KEY_USER_FINANCE+idInc+"','"+req.getParameter("user")+"','Raw Material','"+(-1*price)+"')");
    //      }
    accountingFinance(req.getParameter("user"), "Advertisement", price, false);

    srs = db.getJdbc()
            .queryForRowSet("select id,turn from product_advertisement where [user]='"
                    + req.getParameter("user") + "' and product='" + req.getParameter("product")
                    + "' and [zone]='" + zone + "' and ads='" + req.getParameter("ads") + "'");
    if (srs.next())
        sqlL.add("update product_advertisement set turn='"
                + (srs.getLong("turn") + (Long.parseLong(req.getParameter("turn")))) + "' where id='"
                + srs.getString("id") + "'");
    else {
        idInc = getUniqueIncrementIdNew("product_advertisement");
        sqlL.add("insert into product_advertisement values ('" + KEY_PRODUCT_ADVERTISEMENT + idInc + "','"
                + req.getParameter("user") + "','" + req.getParameter("product") + "','" + zone + "','"
                + req.getParameter("ads") + "','" + req.getParameter("turn") + "')");
    }

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

    val = gson.toJson(money);

    return val;
}

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

public String fixEquipment(HttpServletRequest req) {
    String val = "", sqls[];
    double money, price;

    //0=internal error
    //1=uang user kurang

    SqlRowSet srs1 = db.getJdbc().queryForRowSet(
            "select money from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'"), srs2;
    if (srs1.next())
        money = srs1.getDouble("money");
    else/*from  w  ww  .j  ava2  s .c  o  m*/
        return "0";

    srs1 = db.getJdbc().queryForRowSet(
            "select durability,buy_price from list_equipment where id='" + req.getParameter("id") + "'");
    if (srs1.next())
        price = ((100 - srs1.getDouble("durability")) / 100) * srs1.getDouble("buy_price");
    else
        return "0";

    if (money < price)
        return "1";

    money -= price;

    ArrayList<String> sqlL = new ArrayList<String>();
    sqlL.add("update businessgame.dbo.[user] set money='" + (money) + "' where name='"
            + req.getParameter("user") + "'");
    sqlL.add("update list_equipment set durability='95.00' where id='" + req.getParameter("id") + "'");

    sqls = new String[sqlL.size()];
    sqlL.toArray(sqls);
    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=(select id from storage where [user]='"
                    + req.getParameter("user")
                    + "' and [zone]=(select [zone] from businessgame.dbo.[user] where name='"
                    + req.getParameter("user")
                    + "')) and storage_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment");
    ArrayList<StorageEquipment> storageEquipments = new ArrayList<StorageEquipment>();
    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()) {
            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(money));
    data.add(gson.toJson(storageEquipments));

    val = gson.toJson(data);

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

    gc();

    return val;
}

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

/**
 * Generate the 13-digit unique id based on the current time millis provided by the system
 * (System.currentTimeMillis()) plus 3-digit incremental value.
 * //from w w  w  .  j av a 2  s  .c  o m
 * @param table The table that'll be used.
 * @return The 13-digit unique id plus 3-digit incremental value.
 */
private String getUniqueIncrementIdNew(String table) {
    String val = "", sqls[];
    int counter;
    long curMillis, millis;
    ArrayList<String> sqlL = new ArrayList<String>();

    SqlRowSet srs = db.getJdbc().queryForRowSet("select [value] from info_values where name='inc_" + table
            + "' union select [value] from info_values where name='last_inc_set_millis'");
    if (srs.next()) {
        counter = Integer.parseInt(srs.getString("value"));
    } else
        return val;

    curMillis = System.currentTimeMillis();

    if (srs.next())
        millis = Long.parseLong(srs.getString("value"));
    else
        return val;

    if (millis < curMillis) {
        millis = curMillis;
        counter = 0;
        sqlL.add("update info_values set [value]='" + millis + "' where name='last_inc_set_millis'");
        sqlL.add("update info_values set [value]='0' where substring(name,1,4)='inc_'");
    }

    if (counter > 99)
        val = "" + counter;
    else if (counter > 9)
        val = "0" + counter;
    else
        val = "00" + counter;
    sqlL.add("update info_values set [value]='" + (counter + 1) + "' where name='inc_" + table + "'");

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

    return millis + val;
}

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

public String buySectorBlueprint(HttpServletRequest req) {
    String val = "", idInc, sqls[];
    double money, price, cost;
    int level, userLevel;
    ArrayList<String> sqlL = new ArrayList<String>();

    //0=internal error
    //1=uang ga cukup
    //2=level belum cukup

    SqlRowSet srs = db.getJdbc().queryForRowSet(
            "select money,[level] from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'");
    if (srs.next()) {
        money = srs.getDouble("money");
        userLevel = srs.getInt("level");
    } else//from w ww .  j a  va 2 s. com
        return "0";

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

    srs = db.getJdbc()
            .queryForRowSet("select [level] from info_sector where name='" + req.getParameter("sector") + "'");
    if (srs.next())
        level = srs.getInt("level");
    else
        return "0";

    srs = db.getJdbc().queryForRowSet(
            "select sector from user_sector_blueprint where [user]='" + req.getParameter("user") + "'");
    ArrayList<String> userSectors = new ArrayList<String>();
    while (srs.next()) {
        userSectors.add(srs.getString("sector"));
    }

    price *= userSectors.size();

    if (money < price)
        return "1";

    if (userLevel < level)
        return "2";

    money -= price;
    if (userLevel == level)
        userLevel = level + 1;

    idInc = getUniqueIncrementIdNew("user_sector_blueprint");
    sqlL.add("insert into user_sector_blueprint values ('" + KEY_USER_SECTOR_BLUEPRINT + idInc + "','"
            + req.getParameter("user") + "','" + req.getParameter("sector") + "')");
    sqlL.add("update businessgame.dbo.[user] set money='" + money + "', [level]='" + userLevel
            + "' where name='" + req.getParameter("user") + "'");
    System.out.println("update businessgame.dbo.[user] set money='" + money + "', [level]='" + userLevel
            + "' where name='" + req.getParameter("user") + "'");

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

    srs = db.getJdbc()
            .queryForRowSet("select cost from info_sector where name='" + req.getParameter("sector") + "'");
    if (srs.next()) {
        cost = srs.getDouble("cost");
    } else
        return "0";

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(money));
    data.add(KEY_USER_SECTOR_BLUEPRINT + idInc);
    data.add(gson.toJson(cost));

    val = gson.toJson(data);

    sqlL = null;
    sqls = null;
    idInc = null;
    srs = 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()//from  w ww.  java 2  s  .  com
            .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 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//from  www.j a va  2 s  . c  o m
        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 upgradeStorage(HttpServletRequest req) {
    String val = "", sqls[], user;
    long level;/*from  w  w  w.  j  av a  2s  . co m*/
    double money, price;
    SqlRowSet srs = db.getJdbc()
            .queryForRowSet("select [user],level from storage where id='" + req.getParameter("storage") + "'");
    ArrayList<String> sqlL = new ArrayList<String>();

    if (srs.next()) {
        user = srs.getString("user");
        level = srs.getLong("level");
    } else
        return "0";

    srs = db.getJdbc().queryForRowSet("select money from businessgame.dbo.[user] where name='" + user + "'");
    if (srs.next())
        money = srs.getDouble("money");
    else
        return "0";

    srs = db.getJdbc().queryForRowSet("select [value] from info_values where name='cost_storage_upgrade'");

    if (srs.next())
        price = Double.parseDouble(srs.getString("value"));
    else
        return "0";

    if (money < price)
        return "1";

    money -= price;

    sqlL.add("update businessgame.dbo.[user] set money=" + money + " where name='" + user + "'");
    sqlL.add("update storage set level=" + (level + 1) + " where id='" + req.getParameter("storage") + "'");

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

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(money));
    data.add(checkUserStorage(req));

    val = gson.toJson(data);

    data = null;
    sqlL = null;
    sqls = null;
    srs = null;

    gc();

    return val;
}

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

public String createNewInstallment(HttpServletRequest req) {
    String val = "", idInc, sqls[], draw;
    double money, cost;
    ArrayList<String> sqlL = new ArrayList<String>();

    //0=internal error
    //1=blueprint ga punya (kemungkinan user nge-cheat)
    //2=uang ga cukup

    SqlRowSet srs = db.getJdbc().queryForRowSet("select id from user_sector_blueprint where user='"
            + req.getParameter("user") + "' and sector='" + req.getParameter("type") + "'");
    if (!srs.next())
        return "1";

    srs = db.getJdbc().queryForRowSet("select money from [user] where name='" + req.getParameter("user") + "'");
    if (srs.next())
        money = srs.getDouble("money");
    else/*  w w  w  .  jav  a  2s . co m*/
        return "0";

    srs = db.getJdbc()
            .queryForRowSet("select cost,draw from info_sector where name='" + req.getParameter("type") + "'");
    if (srs.next()) {
        cost = srs.getDouble("cost");
        draw = srs.getString("draw");
    } else
        return "0";

    srs = db.getJdbc().queryForRowSet("select cost from info_zone where id='" + req.getParameter("zone") + "'");
    if (srs.next())
        cost += srs.getDouble("cost");
    else
        return "0";

    if (money < cost)
        return "2";

    money -= cost;

    sqlL.add("update [user] set money='" + money + "' where name='" + req.getParameter("user") + "'");
    idInc = getUniqueIncrementIdNew("installment");
    sqlL.add("insert into installment values ('" + KEY_INSTALLMENT + idInc + "','" + req.getParameter("user")
            + "','" + req.getParameter("zone") + "','" + req.getParameter("type") + "','',0,0,0,0,0)");

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

    Installment tmp = new Installment(KEY_INSTALLMENT + idInc, req.getParameter("type"),
            req.getParameter("zone"), 0, 0, draw, false);

    ArrayList<String> data = new ArrayList<String>();
    data.add(gson.toJson(money));
    data.add(gson.toJson(tmp));

    val = gson.toJson(data);

    sqlL = null;
    sqls = null;
    idInc = null;
    srs = null;
    tmp = null;

    gc();

    return val;
}

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

public String payBorrowedMoney(HttpServletRequest req) {
    String val = "", sqls[], idBorrow;
    double money, loan, pay;
    ArrayList<String> sqlL = new ArrayList<String>();

    //0 = internal error
    //1 = uang lebih kecil dari pay

    SqlRowSet srs = db.getJdbc()
            .queryForRowSet("select id,money,borrow from businessgame.dbo.[user],borrow_bank where name='"
                    + req.getParameter("user") + "' and name=[user]");
    if (srs.next()) {
        money = srs.getDouble("money");
        loan = srs.getDouble("borrow");
        idBorrow = srs.getString("id");
    } else/*www.ja  v  a2  s.  com*/
        return "0";

    pay = Double.parseDouble(req.getParameter("pay"));

    if (money < pay)
        return "1";

    if (pay > loan)
        pay = loan;

    loan -= pay;

    money -= pay;

    sqlL.add("update businessgame.dbo.[user] set money=" + money + " where name='" + req.getParameter("user")
            + "'");
    if (loan > 0)
        sqlL.add("update borrow_bank set borrow=" + loan + " where id='" + idBorrow + "'");
    else
        sqlL.add("delete from borrow_bank where id='" + idBorrow + "'");

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

    val = gson.toJson(money);

    sqlL = null;
    sqls = null;
    srs = null;

    gc();

    return val;
}