List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.l2jfree.gameserver.gameobjects.skills.PlayerSkills.java
public void deleteSkill(L2Skill skill) { if (skill == null) return;/* w w w .j a v a2s . c o m*/ final SkillMap map = getSkillMap(); if (map.remove(skill) == null) return; Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement( "DELETE FROM character_skills WHERE skill_id=? AND charId=? AND class_index=?"); statement.setInt(1, skill.getId()); statement.setInt(2, getOwner().getObjectId()); statement.setInt(3, getOwner().getClassIndex()); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.assignment4.products.Pro_details.java
@PUT @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)// w w w. j a va2 s. c o m public String putProduct(@PathParam("id") int id, String str) throws SQLException { JsonParser p = Json.createParser(new StringReader(str)); Map<String, String> pm = new LinkedHashMap<String, String>(); String key = ""; String val = ""; while (p.hasNext()) { JsonParser.Event event = p.next(); switch (event) { case KEY_NAME: key = p.getString(); break; case VALUE_STRING: val = p.getString(); pm.put(key, val); break; case VALUE_NUMBER: val = p.getString(); pm.put(key, val); break; default: break; } } if (conn == null) { return "Not connected"; } else { String q = "UPDATE product SET name = ?, description = ?, quantity = ? WHERE product_id =?"; PreparedStatement pstmt = conn.prepareStatement(q); pstmt.setString(1, pm.get("name")); pstmt.setString(2, pm.get("description")); pstmt.setInt(3, Integer.parseInt(pm.get("quantity"))); pstmt.setInt(4, id); pstmt.executeUpdate(); return "row has been updated into the database"; } }
From source file:com.l2jfree.gameserver.model.entity.Couple.java
public Couple(int coupleId) { _id = coupleId;/*from w w w .j a v a 2 s . co m*/ Connection con = null; try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("Select * from couples where id = ?"); statement.setInt(1, _id); rs = statement.executeQuery(); while (rs.next()) { _player1Id = rs.getInt("player1Id"); _player2Id = rs.getInt("player2Id"); _maried = rs.getBoolean("maried"); _affiancedDate = rs.getLong("affiancedDate"); _weddingDate = rs.getLong("weddingDate"); } statement.close(); } catch (Exception e) { _log.error("Exception: Couple.load(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:net.sf.l2j.gameserver.model.entity.Couple.java
public Couple(int coupleId) { _Id = coupleId;/*from ww w . j av a 2 s.c o m*/ java.sql.Connection con = null; try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("Select * from couples where id = ?"); statement.setInt(1, _Id); rs = statement.executeQuery(); while (rs.next()) { _player1Id = rs.getInt("player1Id"); _player2Id = rs.getInt("player2Id"); _maried = rs.getBoolean("maried"); _affiancedDate = Calendar.getInstance(); _affiancedDate.setTimeInMillis(rs.getLong("affiancedDate")); _weddingDate = Calendar.getInstance(); _weddingDate.setTimeInMillis(rs.getLong("weddingDate")); } statement.close(); this._maried = true; } catch (Exception e) { _log.error("Exception: Couple.load(): " + e.getMessage(), e); } finally { try { con.close(); } catch (Exception e) { } } }
From source file:com.l2jfree.gameserver.model.MacroList.java
private void registerMacroInDb(L2Macro macro) { Connection con = null;/* w w w.ja v a 2 s. c o m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "INSERT INTO character_macroses (charId,id,icon,name,descr,acronym,commands) values(?,?,?,?,?,?,?)"); statement.setInt(1, _owner.getObjectId()); statement.setInt(2, macro.id); statement.setInt(3, macro.icon); statement.setString(4, macro.name); statement.setString(5, macro.descr); statement.setString(6, macro.acronym); TextBuilder sb = new TextBuilder(); for (L2MacroCmd cmd : macro.commands) { sb.append(cmd.type).append(','); sb.append(cmd.d1).append(','); sb.append(cmd.d2); if (cmd.cmd != null && cmd.cmd.length() > 0) sb.append(',').append(cmd.cmd); sb.append(';'); } statement.setString(7, sb.length() > 255 ? sb.toString().substring(0, 254) : sb.toString()); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("could not store macro:", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.model.entity.faction.Faction.java
private void updateDB() { Connection con = null;/*from www .ja va2 s . co m*/ try { PreparedStatement statement; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("update factions set points = ? where id = ?"); statement.setFloat(1, _points); statement.setInt(2, _Id); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("Exception: Faction.load(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.model.MacroList.java
public void restore() { _macroses.clear();/*from w ww. ja va 2 s .c om*/ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT id, icon, name, descr, acronym, commands FROM character_macroses WHERE charId=?"); statement.setInt(1, _owner.getObjectId()); ResultSet rset = statement.executeQuery(); while (rset.next()) { int id = rset.getInt("id"); int icon = rset.getInt("icon"); String name = rset.getString("name"); String descr = rset.getString("descr"); String acronym = rset.getString("acronym"); List<L2MacroCmd> commands = new FastList<L2MacroCmd>(); StringTokenizer st1 = new StringTokenizer(rset.getString("commands"), ";"); while (st1.hasMoreTokens()) { StringTokenizer st = new StringTokenizer(st1.nextToken(), ","); if (st.countTokens() < 3) continue; int type = Integer.parseInt(st.nextToken()); int d1 = Integer.parseInt(st.nextToken()); int d2 = Integer.parseInt(st.nextToken()); String cmd = ""; if (st.hasMoreTokens()) cmd = st.nextToken(); L2MacroCmd mcmd = new L2MacroCmd(commands.size(), type, d1, d2, cmd); commands.add(mcmd); } L2Macro m = new L2Macro(id, icon, name, descr, acronym, commands.toArray(new L2MacroCmd[commands.size()])); _macroses.put(m.id, m); } rset.close(); statement.close(); } catch (Exception e) { _log.warn("could not store shortcuts:", e); } finally { L2DatabaseFactory.close(con); } }
From source file:fll.web.playoff.Playoff.java
/** * Given a team number and playoff round get the performance run number in the * current tournament/*from w w w . ja v a2 s.c om*/ * * @return the run number or -1 if not found * @throws SQLException */ public static int getRunNumber(final Connection connection, final String division, final int teamNumber, final int playoffRound) throws SQLException { final int tournament = Queries.getCurrentTournament(connection); PreparedStatement prep = null; ResultSet rs = null; try { prep = connection.prepareStatement("SELECT run_number FROM PlayoffData" // + " WHERE Tournament = ?" // + " AND event_division = ?" + " AND PlayoffRound = ?" // + " AND Team = ?"); prep.setInt(1, tournament); prep.setString(2, division); prep.setInt(3, playoffRound); prep.setInt(4, teamNumber); rs = prep.executeQuery(); if (rs.next()) { final int runNumber = rs.getInt(1); return runNumber; } else { return -1; } } finally { SQLFunctions.close(rs); SQLFunctions.close(prep); } }
From source file:iddb.runtime.db.model.dao.impl.mysql.UserDAOImpl.java
@Override public List<User> findAll(int offset, int limit, int[] count) { String sqlCount = "select count(id) from user"; String sql = "select * from user order by loginid limit ?,?"; List<User> list = new ArrayList<User>(); Connection conn = null;/*from ww w .j a v a2 s . c om*/ try { conn = ConnectionFactory.getMasterConnection(); Statement stC = conn.createStatement(); ResultSet rsC = stC.executeQuery(sqlCount); if (rsC.next()) { count[0] = rsC.getInt(1); } PreparedStatement st = conn.prepareStatement(sql); st.setInt(1, offset); st.setInt(2, limit); ResultSet rs = st.executeQuery(); while (rs.next()) { User user = new User(); loadUser(user, rs); list.add(user); } } catch (SQLException e) { logger.error("findAll: {}", e); } catch (IOException e) { logger.error("findAll: {}", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } return list; }
From source file:com.l2jfree.gameserver.model.entity.faction.FactionMember.java
private void updateDb() { Connection con = null;//from w w w . j a v a 2s.com try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement( "UPDATE faction_members SET faction_points=?,contributions=?,faction_id=? WHERE player_id=?"); statement.setInt(1, _factionPoints); statement.setInt(2, _contributions); statement.setInt(3, _factionId); statement.setInt(4, _playerId); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("Exception: FactionMember.updateDb(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }