Example usage for java.sql PreparedStatement setInt

List of usage examples for java.sql PreparedStatement setInt

Introduction

In this page you can find the example usage for java.sql PreparedStatement setInt.

Prototype

void setInt(int parameterIndex, int x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java int value.

Usage

From source file:biblivre3.acquisition.order.BuyOrderDAO.java

public boolean deleteBuyOrder(BuyOrderDTO dto) {
    Connection conInsert = null;//from ww w  . j  a v a 2s  . c o m
    try {
        conInsert = getDataSource().getConnection();
        final String sqlInsert = " DELETE FROM acquisition_order " + " WHERE serial_order = ?; ";
        PreparedStatement pstInsert = conInsert.prepareStatement(sqlInsert);
        pstInsert.setInt(1, dto.getSerial());
        return pstInsert.executeUpdate() > 0;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new DAOException(e.getMessage());
    } finally {
        closeConnection(conInsert);
    }
}

From source file:com.imagelake.control.InterfaceDAOImp.java

public boolean insertInterface(Interfaces inf) {
    boolean ok = false;
    try {/*from  w ww  .  j av a 2 s. co m*/
        String sql = "INSERT INTO interfaces(url,display_name,state) VALUES(?,?,?)";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setString(1, inf.getUrl());
        ps.setString(2, inf.getDisplay_name());
        ps.setInt(3, inf.getState());

        int i = ps.executeUpdate();
        if (i > 0) {
            ok = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ok;
}

From source file:com.wso2telco.dep.reportingservice.dao.OperatorDAO.java

/**
 * Fill operator trace./*w  w w .  j av a 2  s.c o  m*/
 *
 * @param applicationId the application id
 * @param operatorId the operator id
 * @param lstapproval the lstapproval
 * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception
 * @throws SQLException the SQL exception
 */
public static void fillOperatorTrace(int applicationId, String operatorId, List<Approval> lstapproval)
        throws APIMgtUsageQueryServiceClientException, SQLException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String sql = "SELECT applicationid as application_id ,2 as type, 'APPO' as name, operatorid, (case isactive when 0 then 'PENDING' when 1 then 'APPROVED' else 'REJECTED' end) as isactive, '' as api_name, created_date,lastupdated_date "
            + "FROM " + ReportingTable.OPERATORAPPS + " where operatorid like ? and applicationid = ? "
            + "UNION ALL SELECT applicationid as application_id, 4 as type,'SUBO' as name, openp.operatorid as operatorid, (case enp.isactive when 0 then 'PENDING' when 1 then 'APPROVED' else 'REJECTED' end) as isactive, openp.api as api_name, enp.created_date,enp.lastupdated_date "
            + "FROM " + ReportingTable.ENDPOINTAPPS + " enp," + ReportingTable.OPERATORENDPOINTS
            + " openp WHERE " + "enp.endpointid = openp.id and openp.operatorid like ? and applicationid = ? "
            + "ORDER BY type,api_name, operatorid";

    try {
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB);
        ps = conn.prepareStatement(sql);
        ps.setInt(2, applicationId);
        ps.setInt(4, applicationId);

        if (operatorId.equalsIgnoreCase("%")) {
            ps.setString(1, "%");
            ps.setString(3, "%");
        } else {
            ps.setInt(1, Integer.parseInt(operatorId));
            ps.setInt(3, Integer.parseInt(operatorId));
        }

        rs = ps.executeQuery();
        while (rs.next()) {
            Approval temp = new Approval(rs.getString("application_id"), rs.getString("type"),
                    rs.getString("name"), rs.getInt("operatorid"), rs.getString("isactive"), "",
                    rs.getString("api_name"), "", rs.getString("created_date"),
                    rs.getString("lastupdated_date"));
            lstapproval.add(temp);
        }
    } catch (Exception e) {
        log.error("Error occured while getting operator names from the database" + e);
    } finally {
        DbUtils.closeAllConnections(ps, conn, rs);
    }
}

From source file:com.imagelake.control.PaymentPreferenceDAOImp.java

@Override
public List<PaymentPreferences> getUserEarningHistory(int user_id) {
    List<PaymentPreferences> li = new ArrayList<PaymentPreferences>();
    try {/*from  ww  w . ja  va 2  s . c o  m*/
        String sql = "SELECT * FROM payment_preferences WHERE user_id=?";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setInt(1, user_id);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            PaymentPreferences pp = new PaymentPreferences();
            pp.setAcc_type(rs.getInt(5));
            pp.setAdm_id(rs.getInt(6));
            pp.setAmount(rs.getDouble(7));
            pp.setConf_date(rs.getString(4));
            pp.setDate(rs.getString(3));
            pp.setPpid(rs.getInt(1));
            pp.setState(rs.getInt(8));
            pp.setUser_id(rs.getInt(2));
            System.out.println("getting...");
            li.add(pp);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return li;
}

From source file:com.imagelake.control.PaymentPreferenceDAOImp.java

@Override
public PaymentPreferences getPendingEarning(int uid, int state) {
    PaymentPreferences pp = null;/*from   w  w  w  . ja  v a  2  s . c o m*/
    try {
        String sql = "SELECT * FROM payment_preferences WHERE user_id=? AND state=?";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setInt(1, uid);
        ps.setInt(2, state);

        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            pp = new PaymentPreferences();
            pp.setAcc_type(rs.getInt(5));
            pp.setAdm_id(rs.getInt(6));
            pp.setAmount(rs.getDouble(7));
            pp.setConf_date(rs.getString(4));
            pp.setDate(rs.getString(3));
            pp.setPpid(rs.getInt(1));
            pp.setState(rs.getInt(8));
            pp.setUser_id(rs.getInt(2));
            System.out.println("getting...");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return pp;
}

From source file:com.imagelake.control.PaymentPreferenceDAOImp.java

@Override
public List<PaymentPreferences> getUserEarnedHistory(int uid, int state) {
    ArrayList<PaymentPreferences> li = new ArrayList<PaymentPreferences>();
    try {//from  ww w  . ja  va2s. c o m
        String sql = "SELECT * FROM payment_preferences WHERE user_id=? AND state=?";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setInt(1, uid);
        ps.setInt(2, state);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            PaymentPreferences pp = new PaymentPreferences();
            pp.setAcc_type(rs.getInt(5));
            pp.setAdm_id(rs.getInt(6));
            pp.setAmount(rs.getDouble(7));
            pp.setConf_date(rs.getString(4));
            pp.setDate(rs.getString(3));
            pp.setPpid(rs.getInt(1));
            pp.setState(rs.getInt(8));
            pp.setUser_id(rs.getInt(2));
            System.out.println("getting...");
            li.add(pp);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return li;
}

From source file:net.sf.l2j.gameserver.instancemanager.CoupleManager.java

public void deleteCouple(int coupleId) {
    int index = getCoupleIndex(coupleId);
    Couple couple = getCouples().get(index);
    if (couple != null) {
        L2PcInstance player1 = (L2PcInstance) L2World.getInstance().findObject(couple.getPlayer1Id());
        L2PcInstance player2 = (L2PcInstance) L2World.getInstance().findObject(couple.getPlayer2Id());
        L2ItemInstance item = null;//  w  w  w.  j  a v a 2s.  c om
        if (player1 != null) {
            player1.setPartnerId(0);
            player1.setMaried(false);
            player1.setCoupleId(0);
            item = player1.getInventory().getItemByItemId(9140);
            if (player1.isOnline() == 1 && item != null) {
                player1.destroyItem("Removing Cupids Bow", item, player1, true);
                player1.getInventory().updateDatabase();
            }
            if (player1.isOnline() == 0 && item != null) {
                Integer PlayerId = player1.getObjectId();
                Integer ItemId = 9140;
                java.sql.Connection con = null;
                try {
                    con = L2DatabaseFactory.getInstance().getConnection();
                    PreparedStatement statement = con
                            .prepareStatement("delete from items where owner_id = ? and item_id = ?");
                    statement.setInt(1, PlayerId);
                    statement.setInt(2, ItemId);
                    statement.execute();
                    statement.close();
                } catch (Exception e) {
                } finally {
                    try {
                        con.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
        if (player2 != null) {
            player2.setPartnerId(0);
            player2.setMaried(false);
            player2.setCoupleId(0);
            item = player2.getInventory().getItemByItemId(9140);
            if (player2.isOnline() == 1 && item != null) {
                player2.destroyItem("Removing Cupids Bow", item, player2, true);
                player2.getInventory().updateDatabase();
            }
            if (player2.isOnline() == 0 && item != null) {
                Integer Player2Id = player2.getObjectId();
                Integer Item2Id = 9140;
                java.sql.Connection con = null;
                try {
                    con = L2DatabaseFactory.getInstance().getConnection();
                    PreparedStatement statement = con
                            .prepareStatement("delete from items where owner_id = ? and item_id = ?");
                    statement.setInt(1, Player2Id);
                    statement.setInt(2, Item2Id);
                    statement.execute();
                    statement.close();
                } catch (Exception e) {
                } finally {
                    try {
                        con.close();
                    } catch (Exception e) {
                    }
                }
            }
        }
        couple.divorce();
        getCouples().remove(index);
    }
}

From source file:com.imagelake.control.PaymentPreferenceDAOImp.java

public JSONArray getPayments(int state) {
    JSONArray ja = new JSONArray();
    PaymentAccountDAOImp pad = new PaymentAccountDAOImp();
    try {/*  w  w  w .  j a  v  a2  s  . c  o m*/
        String sql = "SELECT * FROM payment_preferences WHERE state=?";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setInt(1, state);
        ResultSet rs = ps.executeQuery();
        int no = 0;
        while (rs.next()) {
            no++;
            JSONObject jo = new JSONObject();
            jo.put("id", rs.getString(1));
            jo.put("userid", rs.getString(2));
            jo.put("reqdate", rs.getString(3));
            jo.put("acctype", pad.getPaymetAccountName(rs.getInt(5)));
            jo.put("amount", rs.getDouble(7));
            jo.put("state", rs.getInt(8));
            jo.put("email", rs.getString(9));
            jo.put("no", no);
            ja.add(jo);
        }
        return ja;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return ja;
}

From source file:biblivre3.acquisition.request.RequestDAO.java

public boolean deleteRequest(RequestDTO dto) {
    Connection conInsert = null;/*from w  ww.  java  2  s.c o  m*/
    try {
        conInsert = getDataSource().getConnection();
        final String sqlInsert = " DELETE FROM acquisition_requisition " + " WHERE serial_requisition = ?; ";
        PreparedStatement pstInsert = conInsert.prepareStatement(sqlInsert);
        pstInsert.setInt(1, dto.getSerial());
        return pstInsert.executeUpdate() > 0;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new DAOException(e.getMessage());
    } finally {
        closeConnection(conInsert);
    }
}