Skip to content

[HELP] Java Script

Featured Replies

Hi all i decided to write my custom community buffer.

first i wrote only to save buffs and get it and then i decided to add Scheme Function in it so i stucked here.

can anyone help me how to add String Name  in the code to save also in sql?

 

private void saveBuff()
{
	Map<Integer, Integer> ceffects = new FastMap<Integer, Integer>();	
	L2Character character;
    if (character == null)
	{
		return;
	}		
	if (ceffects.isEmpty())
	{
		return;
	}
	if(character.getAllEffects() == null)
	{
		return;
	}	
    for (L2Effect cureffect : character.getAllEffects())
    {
		int idSklll = cureffect.getSkill().getId();
		int lvlSklll = cureffect.getLevel();
		if(character.getAllEffects() != null)
		{
			ceffects.put(idSklll, lvlSklll);// TODO support for Scheme String Name
		}	
	}
	this._bbsBuff.clear();
	this._bbsBuff.putAll(ceffects);
	saveBuffSQL();
}

private void saveBuffSQL()
{
	try(Connection con = L2DatabaseFactory.getInstance().getConnection())
	{		
		PreparedStatement statement = con.prepareStatement("DELETE FROM character_bbs_buff_save WHERE charId=?");
		statement.setInt(1, getObjectId());
		statement.execute();
		statement.close();

		for (Map.Entry<Integer, Integer> entry : ceffects.entrySet())
		{
			statement = con.prepareStatement("INSERT INTO character_bbs_buff_save (charId,skill_id,skill_level) VALUES (?,?,?)");
			statement.setInt(1, getObjectId());
			statement.setInt(2, entry.getKey().intValue());
			statement.setInt(3, entry.getValue().intValue());
			statement.execute();
			statement.close();
		}
	}
	catch (Exception e)
	{
		_log.log(Level.WARNING, "Could not store char effect data: ", e);
	}				
}

statement.setString(1, parameter_here)

 

I love the photos very much, where did you take it? The light, shadow and portion are superb and excellent, wish i could take photos like yours pretty soon! By the way i'd like to recommend a good shopping website, all the replica tote bags are manufactured with 100% real leather,durable hardwares ,excellent craftsmanship, click here  right now!

  • Author
statement.setString(1, parameter_here)

is it correct ?

 

private void saveBuff(L2PcInstance activeChar, String SchemeName)
{
	L2Character character = activeChar;
    if (character == null)
	{
		return;
	}		
	if (ceffects.isEmpty())
	{
		return;
	}
	if(character.getAllEffects() == null)
	{
		return;
	}	
    for (L2Effect cureffect : character.getAllEffects())
    {
		int idSklll = cureffect.getSkill().getId();
		int lvlSklll = cureffect.getLevel();
		if(character.getAllEffects() != null)
		{
			ceffects.put(idSklll, lvlSklll);// TODO support for Scheme String Name
		}	
	}
	this._bbsBuff.clear();
	this._bbsBuff.putAll(ceffects);
	saveBuffSQL(activeChar,SchemeName);
}	

private void saveBuffSQL(L2PcInstance activeChar, String SchemeName)
{
	try(Connection con = L2DatabaseFactory.getInstance().getConnection())
	{		
		PreparedStatement statement = con.prepareStatement("DELETE FROM character_bbs_buff_save WHERE charId=?");
		statement.setInt(1, activeChar.getObjectId());
		statement.execute();
		statement.close();

		for (Map.Entry<Integer, Integer> entry : ceffects.entrySet())
		{
			statement = con.prepareStatement("INSERT INTO character_bbs_buff_save (charId,scheme_name,skill_id,skill_level) VALUES (?,?,?,?)");
			statement.setInt(1, activeChar.getObjectId());
			statement.setString(2, SchemeName);
			statement.setInt(3, entry.getKey().intValue());
			statement.setInt(4, entry.getValue().intValue());
			statement.execute();
			statement.close();
		}
	}
	catch (Exception e)
	{
		_log.log(Level.WARNING, "Could not store char effect data: ", e);
	}				
}	

why are you using execute() and not executeupdate()? also change your setstring statement

statement.setString(4, SchemeName);

  • Author

whats difference between execute() and executeupdate()?

execute() will try to update everything into the SQl database, but executeUpdate() will online update INSERT,DELETE,UPDATE commands which in your case is a lot faster

Create an account or sign in to comment

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.