List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:oobbit.orm.LinkConnections.java
public ArrayList<LinkConnection> getAll(int linkId) throws SQLException, NothingWasFoundException { PreparedStatement statement = getConnection() .prepareStatement("SELECT * FROM `connections` WHERE `source_link_id` = ?;"); statement.setInt(1, linkId); return parseResults(statement.executeQuery()); }
From source file:com.l2jfree.gameserver.idfactory.BitSetRebuildFactory.java
public synchronized void initialize() { _log.info("starting db rebuild, good luck"); _log.info("this will take a while, dont kill the process or power off youre machine!"); try {// w w w . j a v a 2s .c o m _freeIds = new BitSet(PrimeFinder.nextPrime(100000)); _freeIds.clear(); _freeIdCount = new AtomicInteger(FREE_OBJECT_ID_SIZE); List<Integer> used_ids = new FastList<Integer>(); // first get all used ids for (int usedObjectId : extractUsedObjectIDTable()) used_ids.add(usedObjectId); _nextFreeId = new AtomicInteger(_freeIds.nextClearBit(0)); Connection con = null; con = L2DatabaseFactory.getInstance().getConnection(con); int nextid; int changedids = 0; // now loop through all already used oids and assign a new clean one for (int i : extractUsedObjectIDTable()) { for (;;) //danger ;) { nextid = getNextId(); if (!used_ids.contains(nextid)) break; } for (String update : ID_UPDATES) { PreparedStatement ps = con.prepareStatement(update); ps.setInt(1, nextid); ps.setInt(2, i); ps.execute(); ps.close(); changedids++; } } _log.info( "database rebuild done, changed " + changedids + " ids, set idfactory config to BitSet! ^o^/"); System.exit(0); } catch (Exception e) { _log.fatal("could not rebuild database! :", e); System.exit(0); } }
From source file:com.imagelake.control.KeyWordsDAOImp.java
@Override public boolean removeKeyWord(int key_word_id) { boolean ok = false; try {//from w w w . j a va 2s .c om String sql = "DELETE FROM key_words WHERE key_words_id=?"; Connection con = DBFactory.getConnection(); PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, key_word_id); int i = ps.executeUpdate(); if (i > 0) { ok = true; } else { ok = false; } } catch (Exception e) { e.printStackTrace(); } return ok; }
From source file:com.l2jfree.gameserver.instancemanager.FriendListManager.java
public synchronized boolean insert(Integer objId1, Integer objId2) { boolean modified = false; modified |= _friends.containsKey(objId1) && _friends.get(objId1).add(objId2); modified |= _friends.containsKey(objId2) && _friends.get(objId2).add(objId1); if (!modified) return false; Connection con = null;//from w w w . j a va2s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(INSERT_QUERY); statement.setInt(1, Math.min(objId1, objId2)); statement.setInt(2, Math.max(objId1, objId2)); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } return true; }
From source file:com.spend.spendService.MainPage.java
public int createCrawl(String queryText, String crawlerName) { try {/*w w w. j a va 2s. c o m*/ String SQL = "SELECT max(crawlid) FROM crawlrecord"; Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(SQL); int id = 0; if (rs.next()) { try { id = rs.getInt(1); } catch (Exception ex) { } } rs.close(); String SQLi = "INSERT INTO crawlrecord (crawlid,crawlerName,queryText) VALUES (?,?,?)"; PreparedStatement pstmt = con.prepareStatement(SQLi); pstmt.setInt(1, id + 1); pstmt.setString(2, crawlerName); pstmt.setString(3, queryText); pstmt.executeUpdate(); pstmt.close(); stmt.close(); return id + 1; } catch (Exception ex) { System.out.println(ex.getMessage()); } return 0; }
From source file:com.imagelake.control.KeyWordsDAOImp.java
@Override public List<KeyWords> getkeyWordList(int images_images_id) { List<KeyWords> list = new ArrayList<KeyWords>(); try {/*from w ww .j av a2s . co m*/ String sql = "SELECT * FROM key_words WHERE images_images_id=?"; Connection con = DBFactory.getConnection(); PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, images_images_id); ResultSet rs = ps.executeQuery(); while (rs.next()) { KeyWords kw = new KeyWords(); kw.setImages_images_id(rs.getInt(3)); kw.setKey_word(rs.getString(2)); kw.setKey_words_id(rs.getInt(1)); list.add(kw); } } catch (Exception e) { e.printStackTrace(); } return list; }
From source file:com.l2jfree.gameserver.instancemanager.FriendListManager.java
public synchronized boolean remove(Integer objId1, Integer objId2) { boolean modified = false; modified |= _friends.containsKey(objId1) && _friends.get(objId1).remove(objId2); modified |= _friends.containsKey(objId2) && _friends.get(objId2).remove(objId1); if (!modified) return false; Connection con = null;//from w w w. j ava 2s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(DELETE_QUERY); statement.setInt(1, objId1); statement.setInt(2, objId2); statement.setInt(3, objId2); statement.setInt(4, objId1); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } return true; }
From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java
@Override public void save(Schedule schedule) { jdbcTemplate.execute("INSERT INTO schedule (parent_id, week, activity_date, create_date, update_date) " + "VALUES (?, ?, ?, NOW(), NOW());", (PreparedStatement preparedStatement) -> { preparedStatement.setLong(1, schedule.getParentId()); preparedStatement.setInt(2, schedule.getWeek()); preparedStatement.setDate(3, Date.valueOf(schedule.getActivityDate())); preparedStatement.execute(); return null; });//w ww. j av a 2 s.com }
From source file:com.l2jfree.gameserver.datatables.RecordTable.java
public synchronized void update() { final int onlinePlayerCount = L2World.getInstance().getAllPlayersCount(); if (_record < onlinePlayerCount) { Connection con = null;// www . java2s .c o m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("INSERT INTO record (maxplayer, date) VALUES (?, NOW())"); statement.setInt(1, onlinePlayerCount); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } load(); } }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminRepairChar.java
private void handleRepair(String command, L2Player activeChar) { String[] parts = command.split(" "); if (parts.length != 2) return;/*ww w . j ava2s . c o m*/ final Integer objId = CharNameTable.getInstance().getByName(parts[1]); if (objId == 0) return; Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("UPDATE characters SET x=17867, y=170259, z=-3450 WHERE charId=?"); statement.setInt(1, objId); statement.execute(); statement.close(); statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?"); statement.setInt(1, objId); statement.execute(); statement.close(); statement = con .prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=? AND loc=\"PAPERDOLL\""); statement.setInt(1, objId); statement.execute(); statement.close(); activeChar.sendMessage("Character " + parts[1] + " got repaired."); } catch (Exception e) { _log.warn("Could not repair character: ", e); } finally { L2DatabaseFactory.close(con); } }