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:at.alladin.rmbt.db.fields.IntField.java

@Override
public void getField(final PreparedStatement ps, final int idx) throws SQLException {
    if (value == null)
        ps.setNull(idx, Types.INTEGER);
    else/*from  ww w  .ja va 2s .  c  o m*/
        ps.setInt(idx, value);
}

From source file:cai.flow.packets.V8_FlowProtoPort.java

void fill_specific(PreparedStatement add_raw_stm) throws SQLException {
    add_raw_stm.setInt(13, (int) prot);
    add_raw_stm.setInt(14, (int) srcport);
    add_raw_stm.setInt(15, (int) dstport);
    add_raw_stm.setString(16, Params.getCurrentTime());
}

From source file:com.wso2telco.dao.TransactionDAO.java

/**
 * Insert transaction log.//from  w  ww.j  a  va2  s  . c  o  m
 *
 * @param transaction the transaction
 * @param contextId   the context id
 * @param statusCode  the status code
 * @throws Exception the exception
 */
public static void insertTransactionLog(Transaction transaction, String contextId, int statusCode)
        throws Exception {

    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DbUtil.getConnectDBConnection();
        String query = "INSERT INTO mcx_cross_operator_transaction_log (tx_id, tx_status, batch_id, api_id, "
                + "client_id," + " application_state, sub_op_mcc, sub_op_mnc, timestamp_start, timestamp_end, "
                + "exchange_response_code)" + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        ps = conn.prepareStatement(query);
        ps.setString(1, transaction.getTx_id());
        ps.setString(2, transaction.getTx_status());
        ps.setString(3, contextId);
        ps.setString(4, transaction.getApi().getId());
        ps.setString(5, transaction.getClient_id());
        ps.setString(6, transaction.getApplication_state());
        ps.setString(7, transaction.getSubscriber_operator().getMcc());
        ps.setString(8, transaction.getSubscriber_operator().getMnc());
        ps.setString(9, transaction.getTimestamp().getStart());
        ps.setString(10, transaction.getTimestamp().getEnd());
        ps.setInt(11, statusCode);
        ps.execute();

    } catch (SQLException e) {
        handleException("Error in inserting transaction log record : " + e.getMessage(), e);
    } finally {
        DbUtil.closeAllConnections(ps, conn, null);
    }
}

From source file:net.freechoice.model.orm.Map_Account.java

@Override
public PreparedStatementCreator createInsert(final FC_Account account) {

    return new PreparedStatementCreator() {
        @Override/*from ww w .ja  va  2 s.  c  om*/
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con.prepareStatement(
                    "insert into FC_Account(" + "id_user_, balance)" + " values(?, ?)", RET_ID);
            ps.setInt(1, account.id_user_);
            ps.setBigDecimal(2, account.balance);
            return ps;
        }
    };
}

From source file:net.sf.l2j.gameserver.model.entity.ClanHallSiege.java

public long restoreSiegeDate(int ClanHallId) {
    long res = 0;
    Connection con = null;//from   www .j a v  a2 s . co m
    try {
        con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement = con.prepareStatement("SELECT siege_data FROM clanhall_siege WHERE id=?");
        statement.setInt(1, ClanHallId);
        ResultSet rs = statement.executeQuery();
        if (rs.next())
            res = rs.getLong("siege_data");
        rs.close();
        statement.close();
    } catch (Exception e) {
        _log.error("Exception: can't get clanhall siege date: " + e.getMessage(), e);
    } finally {
        try {
            if (con != null)
                con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    return res;
}

From source file:com.l2jfree.gameserver.idfactory.StackIDFactory.java

private int insertUntil(int[] tmp_obj_ids, int idx, int N, Connection con) throws SQLException {
    int id = tmp_obj_ids[idx];
    if (id == _tempOID) {
        _tempOID++;//from  w  ww.ja v a  2s  .co  m
        return N;
    }
    // Check these IDs not present in DB
    if (Config.BAD_ID_CHECKING) {
        for (String check : ID_CHECKS) {
            PreparedStatement ps = con.prepareStatement(check);
            ps.setInt(1, _tempOID);
            //ps.setInt(1, _curOID);
            ps.setInt(2, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                int badId = rs.getInt(1);
                _log.fatal("Bad ID " + badId + " in DB found by: " + check);
                throw new RuntimeException();
            }
            rs.close();
            ps.close();
        }
    }

    //int hole = id - _curOID;
    int hole = id - _tempOID;
    if (hole > N - idx)
        hole = N - idx;
    for (int i = 1; i <= hole; i++) {
        //_log.debugr("Free ID added " + (_tempOID));
        _freeOIDStack.push(_tempOID);
        _tempOID++;
        //_curOID++;
    }
    if (hole < N - idx)
        _tempOID++;
    return N - hole;
}

From source file:net.freechoice.model.orm.Map_Account.java

@Override
public PreparedStatementCreator createUpdate(final FC_Account entity) {

    return new PreparedStatementCreator() {

        @Override//  ww w .ja va  2s  . c o  m
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement(
                    "update FC_Account set id_user_= ? " + ",balance = ? " + " where id = ? ");

            ps.setInt(1, entity.id_user_);
            ps.setBigDecimal(2, entity.balance);
            ps.setInt(3, entity.id);
            return ps;
        }
    };
}

From source file:ece356.UserDBAO.java

public static void writeReview(ReviewData review) throws ClassNotFoundException, SQLException, NamingException {
    Connection con = null;/*from w  ww.ja v a  2  s . c  om*/
    PreparedStatement pstmt = null;
    try {
        con = getConnection();
        pstmt = con.prepareStatement(
                "INSERT INTO review (doc_username, patient_username, date, rating, comment) VALUES (?, ?, NOW(), ?, ?);");
        pstmt.setString(1, review.getDoctorUsername());
        pstmt.setString(2, review.getPatientUsername());
        pstmt.setInt(3, review.getRating());
        pstmt.setString(4, review.getComment());
        pstmt.executeUpdate();
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
        if (con != null) {
            con.close();
        }
    }
}

From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java

@Override
public void delete(long parentId, int week) {
    jdbcTemplate.execute("DELETE FROM schedule WHERE parent_id = ? AND week = ?",
            (PreparedStatement preparedStatement) -> {
                preparedStatement.setLong(1, parentId);
                preparedStatement.setInt(2, week);
                preparedStatement.execute();
                return null;
            });//  w w  w  .  j  av  a 2s .  c o  m
}

From source file:fp4f.floorplans.DatabaseLayer.java

HouseItem getHouse(AddressItem selected) {
    HouseItem house = new HouseItem();
    try {//from w w  w . j  a  v a  2 s  .  c  o  m
        PreparedStatement getter = con.prepareStatement("select * from houses where id = ?");
        getter.setInt(1, selected.HouseId);
        ResultSet rs = getter.executeQuery();

        house.Id = rs.getInt("id");

        house.Address = rs.getString("address");
        house.Phone = rs.getString("phone");

        house.Adults = rs.getInt("adults");
        house.Children = rs.getInt("children");
        house.Elderly = rs.getInt("elderly");
        house.Pets = rs.getInt("pets");
        house.Salvage = rs.getInt("salvage");
        house.Complexity = rs.getInt("complexity");

        house.Weapons = rs.getBoolean("weapons");

        house.Disabilities = rs.getString("disability");
        house.Combustables = rs.getString("combustables");
        house.Community = rs.getString("community");

        house.Floors = getFloors(house.Id);
    } catch (Exception ex) {
        System.out.println(ex);
    }
    return house;
}