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:com.github.brandtg.switchboard.TestMysqlLogServer.java

@Test
public void testSimpleWrites() throws Exception {
    try (Connection conn = DriverManager.getConnection(jdbc, "root", "")) {
        // Write some rows, so we have binlog entries
        PreparedStatement pstmt = conn.prepareStatement("INSERT INTO simple VALUES(?, ?)");
        for (int i = 0; i < 10; i++) {
            pstmt.setInt(1, i);
            pstmt.setInt(2, i);/*from  www  .  jav a 2s  .com*/
            pstmt.execute();
        }
    }

    pollAndCheck(serverAddress, "/log/test/0", 10, 10);
}

From source file:biblivre3.acquisition.supplier.SupplierDAO.java

public ArrayList<SupplierDTO> listSuppliers(int offset, int limit) {
    ArrayList<SupplierDTO> supplierList = new ArrayList<SupplierDTO>();
    Connection con = null;/*from   ww  w.  j  a  va2s .  co  m*/
    try {
        con = getDataSource().getConnection();
        final String sql = " SELECT * FROM acquisition_supplier "
                + " ORDER BY serial_supplier ASC offset ? limit ? ";
        final PreparedStatement pst = con.prepareStatement(sql);
        pst.setInt(1, offset);
        pst.setInt(2, limit);
        final ResultSet rs = pst.executeQuery();
        if (rs == null) {
            return supplierList;
        }
        while (rs.next()) {
            SupplierDTO dto = this.populateDto(rs);
            supplierList.add(dto);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new DAOException(e.getMessage());
    } finally {
        closeConnection(con);
    }
    return supplierList;
}

From source file:com.l2jfree.gameserver.instancemanager.CastleManager.java

public void removeCirclet(L2ClanMember member, int castleId) {
    if (member == null)
        return;// w  w w . j a  v a  2 s  .c  om
    L2Player player = member.getPlayerInstance();
    int circletId = getCircletByCastleId(castleId);

    if (circletId != 0) {
        // Online Player circlet removal
        if (player != null && player.getInventory() != null) {
            L2ItemInstance circlet = player.getInventory().getItemByItemId(circletId);
            if (circlet != null) {
                if (circlet.isEquipped())
                    player.getInventory().unEquipItemInSlotAndRecord(circlet.getLocationSlot());
                player.destroyItemByItemId("CastleCircletRemoval", circletId, 1, player, true);
            }
            return;
        }
        // Else Offline Player circlet removal
        Connection con = null;
        try {
            con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement statement = con
                    .prepareStatement("DELETE FROM items WHERE owner_id = ? and item_id = ?");
            statement.setInt(1, member.getObjectId());
            statement.setInt(2, circletId);
            statement.execute();
            statement.close();
        } catch (SQLException e) {
            _log.error("Failed to remove castle circlets offline for player " + member.getName(), e);
        } finally {
            L2DatabaseFactory.close(con);
        }
    }
}

From source file:com.nabla.dc.server.xml.settings.XmlCompany.java

public boolean save(final Connection conn, final Map<String, Integer> companyIds, final SaveContext ctx)
        throws SQLException, DispatchException {
    Integer companyId = companyIds.get(getName());
    if (companyId != null) {
        if (ctx.getOption() == SqlInsertOptions.APPEND)
            return true;
        Database.executeUpdate(conn, "UPDATE company SET active=? WHERE id=?;", active, companyId);
        Database.executeUpdate(conn, "DELETE FROM financial_year WHERE company_id=?;", companyId);
        if (accounts != null) {
            if (log.isDebugEnabled())
                log.debug("deleting all accounts of company '" + getName() + "'");
            accounts.clear(conn, companyId);
        }/*from w w w  .  j a v a2s.c o m*/
        if (asset_categories != null)
            asset_categories.clear(conn, companyId);
        if (users != null)
            users.clear(conn, companyId);
    } else {
        companyId = Database.addRecord(conn, "INSERT INTO company (name,uname,active) VALUES(?,?,?);",
                getName(), getName().toUpperCase(), active);
        if (companyId == null)
            throw new InternalErrorException(Util.formatInternalErrorDescription("failed to insert company"));
        companyIds.put(getName(), companyId);
    }
    final Integer financialYearId = Database.addRecord(conn,
            "INSERT INTO financial_year (company_id, name) VALUES(?,?);", companyId, financial_year);
    final PreparedStatement stmt = conn
            .prepareStatement("INSERT INTO period_end (financial_year_id,name,end_date) VALUES(?,?,?);");
    try {
        stmt.setInt(1, financialYearId);
        final Calendar dt = new GregorianCalendar();
        dt.setTime(start_date);
        final SimpleDateFormat financialYearFormat = new SimpleDateFormat("MMM yyyy");
        for (int m = 0; m < 12; ++m) {
            dt.set(GregorianCalendar.DAY_OF_MONTH, dt.getActualMaximum(GregorianCalendar.DAY_OF_MONTH));
            final Date end = new Date(dt.getTime().getTime());
            stmt.setString(2, financialYearFormat.format(end));
            stmt.setDate(3, end);
            stmt.addBatch();
            dt.add(GregorianCalendar.MONTH, 1);
        }
        if (!Database.isBatchCompleted(stmt.executeBatch()))
            throw new InternalErrorException(Util
                    .formatInternalErrorDescription("fail to insert periods for company '" + getName() + "'"));
    } finally {
        stmt.close();
    }
    if (accounts != null)
        accounts.save(conn, companyId);
    return (asset_categories == null || asset_categories.save(conn, companyId, ctx))
            && (users == null || users.save(conn, companyId, ctx));
}

From source file:biblivre3.acquisition.supplier.SupplierDAO.java

public boolean deleteSupplier(SupplierDTO dto) {
    Connection conInsert = null;//from   w  w  w. j a  va 2  s.  co m
    try {
        conInsert = getDataSource().getConnection();
        final String sqlInsert = " DELETE FROM acquisition_supplier " + " WHERE serial_supplier = ?; ";
        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.l2jfree.gameserver.model.entity.GrandBossState.java

public void update() {
    Connection con = null;/*  ww  w . java  2s .  com*/

    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "UPDATE grandboss_intervallist SET respawnDate = ?,state = ? WHERE bossId = ?");
        statement.setLong(1, _respawnDate);
        statement.setInt(2, _state.ordinal());
        statement.setInt(3, _bossId);
        statement.execute();
        statement.close();
        _log.info("update GrandBossState : ID-" + _bossId + ",RespawnDate-" + _respawnDate + ",State-"
                + _state.toString());
    } catch (Exception e) {
        _log.warn("Exeption on update GrandBossState : ID-" + _bossId + ",RespawnDate-" + _respawnDate
                + ",State-" + _state.toString(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:de.whs.poodle.repositories.McWorksheetRepository.java

public int createMcWorksheet(CreateMcWorksheetForm form, int studentId, int courseTermId) {
    return jdbc.query(con -> {
        PreparedStatement ps = con.prepareStatement("SELECT * FROM generate_student_mc_worksheet(?,?,?,?,?)");
        ps.setInt(1, courseTermId);
        ps.setInt(2, studentId);//from  w w w . j  a va 2s  . c om

        Array tagsArray = con.createArrayOf("int4", ObjectUtils.toObjectArray(form.getTags()));
        ps.setArray(3, tagsArray);

        ps.setInt(4, form.getMaximum());
        ps.setBoolean(5, form.isIgnoreAlreadyAnswered());

        return ps;
    }, new ResultSetExtractor<Integer>() {

        @Override
        public Integer extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (!rs.next()) // no results -> generated worksheet had no questions
                return 0;

            return rs.getInt("id");
        }
    });
}

From source file:com.l2jfree.gameserver.communitybbs.bb.Forum.java

/**
 *
 *///from w ww  .  ja  v  a 2s. com
private void getChildren() {
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_parent=?");
        statement.setInt(1, _forumId);
        ResultSet result = statement.executeQuery();

        while (result.next()) {
            Forum f = new Forum(result.getInt("forum_id"), this);
            _children.add(f);
            ForumsBBSManager.getInstance().addForum(f);
        }
        result.close();
        statement.close();
    } catch (Exception e) {
        _log.warn("data error on Forum (children): ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:edu.umd.cs.marmoset.modelClasses.Project.java

public static Project lookupByCourseAndProjectNumber(@Course.PK int coursePK, String projectNumber,
        Connection conn) throws SQLException {
    String query = "SELECT " + ATTRIBUTES + " FROM " + " projects " + " WHERE course_pk = ? "
            + " AND project_number = ? ";

    PreparedStatement stmt = conn.prepareStatement(query);

    stmt.setInt(1, coursePK);
    stmt.setString(2, projectNumber);/*from ww  w.  ja va 2s . c om*/
    return getFromPreparedStatement(stmt);
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java

@Override
public void setMutatiesFileStatus(final long id, final ProcessingStatus status) throws DAOException {
    try {//w  w  w. j a  v a 2  s  .c om
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection
                        .prepareStatement("update bag_mutaties_file set" + " status = ?" + " where id = ?");
                ps.setInt(1, status.ordinal());
                ps.setLong(2, id);
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}