List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.imagelake.control.PaymentPreferenceDAOImp.java
@Override public boolean requestSettle(int prid, int state, int admid, String date) { boolean ok = false; try {/*ww w . j a va 2 s.c o m*/ String sql = "UPDATE payment_preferences SET state=?,adm_id=?," + date + "=? WHERE ppid=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, state); ps.setInt(2, admid); ps.setString(3, mdate); ps.setInt(4, prid); int i = ps.executeUpdate(); if (i > 0) { ok = true; } } catch (Exception e) { e.printStackTrace(); } return ok; }
From source file:com.l2jfree.gameserver.communitybbs.bb.Forum.java
/** * *///from w w w . jav a 2 s . c o m private void load() { Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement("SELECT * FROM forums WHERE forum_id=?"); statement.setInt(1, _forumId); ResultSet result = statement.executeQuery(); if (result.next()) { _forumName = result.getString("forum_name"); //_ForumParent = result.getInt("forum_parent")); _forumPost = result.getInt("forum_post"); _forumType = result.getInt("forum_type"); _forumPerm = result.getInt("forum_perm"); _ownerID = result.getInt("forum_owner_id"); } result.close(); statement.close(); } catch (Exception e) { _log.warn("data error on Forum " + _forumId + " : ", e); } finally { L2DatabaseFactory.close(con); } con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con .prepareStatement("SELECT * FROM topic WHERE topic_forum_id=? ORDER BY topic_id DESC"); statement.setInt(1, _forumId); ResultSet result = statement.executeQuery(); while (result.next()) { Topic t = new Topic(Topic.ConstructorType.RESTORE, result.getInt("topic_id"), result.getInt("topic_forum_id"), result.getString("topic_name"), result.getLong("topic_date"), result.getString("topic_ownername"), result.getInt("topic_ownerid"), result.getInt("topic_type"), result.getInt("topic_reply")); _topic.put(t.getID(), t); if (t.getID() > TopicBBSManager.getInstance().getMaxID(this)) { TopicBBSManager.getInstance().setMaxID(t.getID(), this); } } result.close(); statement.close(); } catch (Exception e) { _log.warn("data error on Forum " + _forumId + " : ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.instancemanager.InstanceManager.java
public void deleteInstanceTime(int playerObjId, int id) { Connection con = null;//from ww w .j a v a 2 s.co m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = null; statement = con.prepareStatement(DELETE_INSTANCE_TIME); statement.setInt(1, playerObjId); statement.setInt(2, id); statement.execute(); statement.close(); _playerInstanceTimes.get(playerObjId).remove(id); } catch (Exception e) { _log.warn("Could not delete character instance time data: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.zuoxiaolong.dao.CommentDao.java
public List<Map<String, String>> getLastComments(final Integer size, final ViewMode viewMode) { return execute(new Operation<List<Map<String, String>>>() { @Override//w w w . j a v a 2 s . com public List<Map<String, String>> doInConnection(Connection connection) { List<Map<String, String>> comments = new ArrayList<Map<String, String>>(); try { PreparedStatement statement = connection .prepareStatement("select * from comments order by create_date DESC limit ? "); statement.setInt(1, size); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { comments.add(transfer(resultSet, viewMode)); } } catch (SQLException e) { error("get comments for size[" + size + "] failed ...", e); } return comments; } }); }
From source file:lineage2.gameserver.dao.CharacterDAO.java
/** * Method deleteCharByObjId.//from w ww. ja v a2s .com * @param objid int */ public void deleteCharByObjId(int objid) { if (objid < 0) { return; } Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("DELETE FROM characters WHERE obj_Id=?"); statement.setInt(1, objid); statement.execute(); } catch (Exception e) { _log.error("", e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:com.adanac.module.blog.dao.CommentDao.java
public boolean updateCount(final int id, final String column, final int count) { return execute(new TransactionalOperation<Boolean>() { @Override/* www .ja va2 s. c om*/ public Boolean doInConnection(Connection connection) { int finalCount = count; if (count <= 0) { finalCount = 1; } try { PreparedStatement preparedStatement = connection.prepareStatement("update comments set " + column + " = " + column + " + " + finalCount + " where id = ?"); preparedStatement.setInt(1, id); int number = preparedStatement.executeUpdate(); return number > 0; } catch (SQLException e) { throw new RuntimeException(e); } } }); }
From source file:com.l2jfree.gameserver.instancemanager.InstanceManager.java
public void setInstanceTime(int playerObjId, int id, long time) { if (!_playerInstanceTimes.containsKey(playerObjId)) restoreInstanceTimes(playerObjId); Connection con = null;/*from w w w .ja v a 2 s . c om*/ try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = null; statement = con.prepareStatement(ADD_INSTANCE_TIME); statement.setInt(1, playerObjId); statement.setInt(2, id); statement.setLong(3, time); statement.setLong(4, time); statement.execute(); statement.close(); _playerInstanceTimes.get(playerObjId).put(id, time); } catch (Exception e) { _log.warn("Could not insert character instance time data: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java
@Override public int create(final Starmark starmark) { GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); this.getJdbcTemplate().update(new PreparedStatementCreator() { @Override/*from ww w .java 2 s . com*/ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = null; ps = conn.prepareStatement(SQL_CREATE, PreparedStatement.RETURN_GENERATED_KEYS); int i = 0; ps.setInt(++i, starmark.getRid()); ps.setInt(++i, starmark.getTid()); ps.setString(++i, starmark.getUid()); ps.setTimestamp(++i, new Timestamp(starmark.getCreateTime().getTime())); return ps; } }, keyHolder); Number key = keyHolder.getKey(); return (key == null) ? -1 : key.intValue(); }
From source file:com.l2jfree.gameserver.model.entity.faction.Faction.java
public Faction(int factionId) { _Id = factionId;/* w w w .j a v a2s.c o m*/ String _classlist = ""; String _npclist = ""; String _titlelist = ""; int _tside = 0; Connection con = null; try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("Select * from factions where id = ?"); statement.setInt(1, getId()); rs = statement.executeQuery(); while (rs.next()) { _name = rs.getString("name"); _joinprice = rs.getInt("price"); _classlist = rs.getString("allowed_classes"); _titlelist = rs.getString("titlelist"); _npclist = rs.getString("npcs"); _points = rs.getFloat("points"); _tside = rs.getInt("side"); } statement.close(); if (_tside <= 2) _side = _tside; if (_classlist.length() > 0) for (String id : _classlist.split(",")) _list_classes.add(Integer.parseInt(id)); if (_npclist.length() > 0) for (String id : _npclist.split(",")) _list_npcs.add(Integer.parseInt(id)); if (_titlelist.length() > 0) for (String id : _titlelist.split(";")) _list_title.put(Integer.valueOf(id.split(",")[0]), id.split(",")[1]); } catch (Exception e) { _log.warn("Exception: Faction load: " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.imagelake.control.PaymentPreferenceDAOImp.java
@Override public boolean AddPaymentPreference(PaymentPreferences pp) { boolean ok = false; try {//from www .j a v a 2 s . co m String sql = "INSERT INTO payment_preferences(user_id,date,conf_date,acc_type,adm_id,amount,state,email) VALUES(?,?,?,?,?,?,?,?)"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, pp.getUser_id()); ps.setString(2, pp.getDate()); ps.setString(3, pp.getConf_date()); ps.setInt(4, pp.getAcc_type()); ps.setInt(5, pp.getAdm_id()); ps.setDouble(6, pp.getAmount()); ps.setInt(7, pp.getState()); ps.setString(8, pp.getEmail()); int i = ps.executeUpdate(); if (i > 0) { ok = true; } } catch (Exception e) { e.printStackTrace(); } return ok; }