Jump to content

Recommended Posts

Posted

***

SQL

***

CREATE TABLE IF NOT EXISTS character_color (
    obj_id decimal(11,0) NOT NULL default '0',
    name_color CHAR(6) NOT NULL DEFAULT 'FFFFFF',
    title_color CHAR(6) NOT NULL DEFAULT 'FFFF77',
    PRIMARY KEY  (obj_Id)
);

 

***

Core

***

private void restoreColor()
    {

        ThreadConnection con = null;

        try
        {
            con = L2DatabaseFactory.getInstance().getConnection();
            FiltredPreparedStatement statement = con.prepareStatement("SELECT name_color,title_color FROM character_color WHERE obj_id=?");
            statement.setInt(1, getObjectId());
            ResultSet rset = statement.executeQuery();
            while (rset.next())
            {
                setNameColor(Integer.decode((new StringBuilder()).append("0x").append(rset.getString("name_color")).toString()).intValue());
                setTitleColor(Integer.decode((new StringBuilder()).append("0x").append(rset.getString("title_color")).toString()).intValue());
            }
            DatabaseUtils.closeDatabaseCSR(con,statement,rset);

        }
        catch (SQLException e)
        {
            setNameColor(0xFFFFFF);
            setTitleColor(0xFFFF77);
        }

    }
     private void storeColor()
    {

        if(getNameColor() == 0xFFFFFF && getTitleColor() == 0xFFFF77)
                    return;
        ThreadConnection con = null;
        FiltredPreparedStatement statement=null;

        try
        {
            
            con = L2DatabaseFactory.getInstance().getConnection();
            statement = con.prepareStatement("UPDATE character_color SET name_color=?,title_color=? WHERE obj_id=?");
            statement.setString(1, Integer.toHexString(getNameColor()).toUpperCase());
            statement.setString(2, Integer.toHexString(getTitleColor()).toUpperCase());
            statement.setInt(3, getObjectId());
            statement.execute();

            DatabaseUtils.closeDatabaseCS(con,statement);


        }
        catch (SQLException e)
        {
            con = L2DatabaseFactory.getInstance().getConnection();
            statement = con.prepareStatement("INSERT INTO character_color(obj_id, name_color, title_color) VALUES (?,?,?)");
            statement.setInt(1, getObjectId());
            statement.setString(2, Integer.toHexString(getNameColor()).toUpperCase());
            statement.setString(3, Integer.toHexString(getTitleColor()).toUpperCase());
            statement.execute();

            DatabaseUtils.closeDatabaseCS(con,statement); 
        }

    }

 

Gredits botvans l2jfree forum

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
Reply to this topic...

×   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...