Jump to content
  • 0

[HELP] Java Script


Question

Posted

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);
	}				
}

6 answers to this question

Recommended Posts

  • 0
Posted

 

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!

  • 0
Posted
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);
	}				
}	

  • 0
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...