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.l2jfree.gameserver.instancemanager.InstanceManager.java

public void restoreInstanceTimes(int playerObjId) {
    if (_playerInstanceTimes.containsKey(playerObjId))
        return; // already restored
    _playerInstanceTimes.put(playerObjId, new FastMap<Integer, Long>());
    Connection con = null;/*w  ww.j a  va2 s.  c  o m*/
    try {
        con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement = con.prepareStatement(RESTORE_INSTANCE_TIMES);
        statement.setInt(1, playerObjId);
        ResultSet rset = statement.executeQuery();

        while (rset.next()) {
            int id = rset.getInt("instanceId");
            long time = rset.getLong("time");
            if (time < System.currentTimeMillis())
                deleteInstanceTime(playerObjId, id);
            else
                _playerInstanceTimes.get(playerObjId).put(id, time);
        }

        rset.close();
        statement.close();
    } catch (Exception e) {
        _log.warn("Could not delete character instance time data: ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

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

/**
 *
 *///from   ww w .j a va  2s. co  m
public void insertindb() {
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)");
        statement.setInt(1, _id);
        statement.setInt(2, _forumId);
        statement.setString(3, _topicName);
        statement.setLong(4, _date);
        statement.setString(5, _ownerName);
        statement.setInt(6, _ownerId);
        statement.setInt(7, _type);
        statement.setInt(8, _cReply);
        statement.execute();
        statement.close();

    } catch (Exception e) {
        _log.warn("error while saving new Topic to db ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.adanac.module.blog.dao.AnswerDao.java

public boolean updateContent(Integer id, String answer) {
    return execute(new TransactionalOperation<Boolean>() {
        @Override//w  w w.jav a  2  s. c  om
        public Boolean doInConnection(Connection connection) {
            try {
                PreparedStatement preparedStatement = connection
                        .prepareStatement("update answers set answer=? where id = ?");
                preparedStatement.setString(1, answer);
                preparedStatement.setInt(2, id);
                int number = preparedStatement.executeUpdate();
                return number > 0;
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    });
}

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

public void insertindb(CPost cp) {
    Connection con = null;//from www. j a v  a 2 s.  com
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "INSERT INTO posts (post_id,post_owner_name,post_ownerid,post_date,post_topic_id,post_forum_id,post_txt) values (?,?,?,?,?,?,?)");
        statement.setInt(1, cp.postId);
        statement.setString(2, cp.postOwner);
        statement.setInt(3, cp.postOwnerId);
        statement.setLong(4, cp.postDate);
        statement.setInt(5, cp.postTopicId);
        statement.setInt(6, cp.postForumId);
        statement.setString(7, cp.postTxt);
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.warn("error while saving new Post to db ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.github.brandtg.switchboard.TestMysqlLogServer.java

@Test
public void testRotateBinlog() 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);// w w w . j a v a  2s. c  o  m
            pstmt.execute();
        }

        // Rotate logs
        Statement stmt = conn.createStatement();
        stmt.execute("FLUSH LOGS");

        // Write more
        for (int i = 10; i < 20; i++) {
            pstmt.setInt(1, i);
            pstmt.setInt(2, i);
            pstmt.execute();
        }
    }

    pollAndCheck(serverAddress, "/log/test/0?count=100", 20, 20);
}

From source file:at.becast.youploader.account.Account.java

public void updateCookie(int id) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    LOG.info("Updating account");
    try {/*from w  ww.ja  va2  s  . c o m*/
        PreparedStatement stmt = c.prepareStatement("UPDATE `accounts` SET `cookie`=? WHERE `id`=?");
        stmt.setString(1, mapper.writeValueAsString(this.cdata));
        stmt.setInt(2, id);
        stmt.execute();
        stmt.close();
    } catch (SQLException e) {
        LOG.error("Could not update account Ex:", e);
    }
}

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

/**
 * @param i//  ww w.  ja  va2 s  .co  m
 */
public void updatetxt(int i) {
    Connection con = null;
    try {
        CPost cp = getCPost(i);
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "UPDATE posts SET post_txt=? WHERE post_id=? AND post_topic_id=? AND post_forum_id=?");
        statement.setString(1, cp.postTxt);
        statement.setInt(2, cp.postId);
        statement.setInt(3, cp.postTopicId);
        statement.setInt(4, cp.postForumId);
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.warn("error while saving new Post to db ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.wabacus.system.datatype.IntType.java

public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype)
        throws SQLException {
    log.debug("setInt(" + iindex + "," + value + ")");
    Object objTmp = label2value(value);
    if (objTmp == null) {
        pstmt.setObject(iindex, null, java.sql.Types.INTEGER);
    } else {//from   w w w . ja  v a  2 s . c om
        pstmt.setInt(iindex, (Integer) objTmp);
    }
}

From source file:com.l2jfree.gameserver.datatables.PetSkillsTable.java

private void load() {
    int npcId = 0;
    int count = 0;

    Connection con = null;//  w  w  w .  ja  va2 s  .com
    try {
        con = L2DatabaseFactory.getInstance().getConnection();
        try {
            PreparedStatement statement = con.prepareStatement(
                    "SELECT id FROM npc WHERE type IN ('L2Pet','L2BabyPet','L2SiegeSummon') ORDER BY id");
            ResultSet petlist = statement.executeQuery();
            Map<Integer, L2PetSkillLearn> map;
            L2PetSkillLearn skillLearn;
            while (petlist.next()) {
                map = new FastMap<Integer, L2PetSkillLearn>();
                npcId = petlist.getInt("id");
                PreparedStatement statement2 = con.prepareStatement(
                        "SELECT minLvl, skillId, skillLvl FROM pets_skills WHERE templateId=? ORDER BY skillId, skillLvl");
                statement2.setInt(1, npcId);
                ResultSet skilltree = statement2.executeQuery();

                while (skilltree.next()) {
                    int id = skilltree.getInt("skillId");
                    int lvl = skilltree.getInt("skillLvl");
                    int minLvl = skilltree.getInt("minLvl");

                    skillLearn = new L2PetSkillLearn(id, lvl, minLvl);
                    map.put(SkillTable.getSkillUID(id, lvl + 1), skillLearn);
                }
                _skillTrees.put(npcId, map);
                skilltree.close();
                statement2.close();

                count += map.size();
                if (_log.isDebugEnabled())
                    _log.info("PetSkillsTable: Skill tree for pet " + npcId + " has " + map.size() + " skills");
            }
            petlist.close();
            statement.close();
        } catch (Exception e) {
            _log.fatal("Error while creating pet skill tree (Pet ID " + npcId + "):", e);
        }
        _log.info("PetSkillsTable: Loaded " + count + " skills.");
    } catch (Exception e) {
        _log.fatal("Error while loading pet skills tables ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

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

public MinEarning getMin(int id) {
    MinEarning me = new MinEarning();
    try {//from  w w  w. ja v a  2s.  c  o  m
        String sql = "SELECT * FROM min_earning WHERE id=?";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setInt(1, id);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            me.setId(rs.getInt(1));
            me.setMinearning(rs.getDouble(2));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return me;
}