Uphillyout Posted January 30, 2010 Posted January 30, 2010 Well... is this code have any mistakes? why does not work? L2PcInstance.java // Character Transformation SQL String Definitions: private static final String SELECT_CHAR_TRANSFORM = "SELECT transform_id FROM characters WHERE charId=?"; private static final String UPDATE_CHAR_TRANSFORM = "UPDATE characters SET transform_id=? WHERE charId=?"; + // Character Color System by =) + private static final String INSERT_CHAR_COLOR = "INSERT INTO character_color(charId, name_color, title_color) VALUES (?,?,?)"; + private static final String SELECT_CHAR_COLOR = "SELECT * FROM character_color WHERE charId=?"; + private static final String UPDATE_CHAR_COLOR = "UPDATE character_color SET name_color=?, title_color=? WHERE charId=?"; ===================================== case L2PcInstance.STORE_PRIVATE_MANUFACTURE: activeChar.sendPacket(new RecipeShopMsg(this)); break; } } + /** + * method fo restore colors from database + * and insert if in database if not exists + * @author =) + */ + public void restoreColor() + { + Connection con = null; + PreparedStatement statement = null; + ResultSet rset = null; + try + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement(SELECT_CHAR_COLOR); + statement.setInt(1, getObjectId()); + rset = statement.executeQuery(); + + if (rset.next()) + { + getAppearance().setNameColor(Integer.decode((new +StringBuilder()).append("0x").append(rset.getString("name_color")).toString()).intValue()); + getAppearance().setTitleColor(Integer.decode((new +StringBuilder()).append("0x").append(rset.getString("title_color")).toString()).intValue()); + } + else + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement(INSERT_CHAR_COLOR); + statement.setInt(1, getObjectId()); + statement.setString(2, Integer.toHexString(getAppearance().getNameColor()).toUpperCase()); + statement.setString(3, Integer.toHexString(getAppearance().getTitleColor()).toUpperCase()); + statement.execute(); + } + } + catch (Exception e) + { + _log.warning("could not restore colors: "+e); + } + finally + { + try{ con.close(); statement.close(); rset.close();} + + catch(SQLException e) {} + } + } + + /** + * Store colors + * @author =) + */ + private void storeColor() + { + + Connection con = null; + PreparedStatement statement = null; + try + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement(UPDATE_CHAR_COLOR); + statement.setString(1, Integer.toHexString(getAppearance().getNameColor()).toUpperCase()); + statement.setString(2, Integer.toHexString(getAppearance().getTitleColor()).toUpperCase()); + statement.setInt(3, getObjectId()); + statement.execute(); + } + catch (Exception e) + { + _log.warning("could not store colors: "+e); + e.printStackTrace(); + } + finally + { + try + { + con.close(); statement.close(); + } + catch(SQLException e) {} + } + } And MYSQL -- ---------------------------------------- -- Table structure for `character_color` -- -- ---------------------------------------- DROP TABLE IF EXISTS `character_color`; CREATE TABLE `character_color` ( `charId` 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 (`charId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------
0 Commodus Posted February 1, 2010 Posted February 1, 2010 Okay , i don't have time right now to tell you what exactly methods are. Check and read this tutorial about java methods : Click Me If you have any problems , do not hesitate to ask.
0 xAddytzu Posted February 1, 2010 Posted February 1, 2010 Okay , i don't have time right now to tell you what exactly methods are. Check and read this tutorial about java methods : Click Me If you have any problems , do not hesitate to ask. and what is the point?
0 Commodus Posted February 1, 2010 Posted February 1, 2010 and what is the point? What do you mean ? He don't know how to call the methods in a code , that's why i gave him this link.
0 Uphillyout Posted February 3, 2010 Author Posted February 3, 2010 What do you mean ? He don't know how to call the methods in a code , that's why i gave him this link. omg)) i know)) btw, why you cant just help ?
Question
Uphillyout
Well... is this code have any mistakes? why does not work?
L2PcInstance.java
// Character Transformation SQL String Definitions: private static final String SELECT_CHAR_TRANSFORM = "SELECT transform_id FROM characters WHERE charId=?"; private static final String UPDATE_CHAR_TRANSFORM = "UPDATE characters SET transform_id=? WHERE charId=?"; + // Character Color System by =) + private static final String INSERT_CHAR_COLOR = "INSERT INTO character_color(charId, name_color, title_color) VALUES (?,?,?)"; + private static final String SELECT_CHAR_COLOR = "SELECT * FROM character_color WHERE charId=?"; + private static final String UPDATE_CHAR_COLOR = "UPDATE character_color SET name_color=?, title_color=? WHERE charId=?"; ===================================== case L2PcInstance.STORE_PRIVATE_MANUFACTURE: activeChar.sendPacket(new RecipeShopMsg(this)); break; } } + /** + * method fo restore colors from database + * and insert if in database if not exists + * @author =) + */ + public void restoreColor() + { + Connection con = null; + PreparedStatement statement = null; + ResultSet rset = null; + try + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement(SELECT_CHAR_COLOR); + statement.setInt(1, getObjectId()); + rset = statement.executeQuery(); + + if (rset.next()) + { + getAppearance().setNameColor(Integer.decode((new +StringBuilder()).append("0x").append(rset.getString("name_color")).toString()).intValue()); + getAppearance().setTitleColor(Integer.decode((new +StringBuilder()).append("0x").append(rset.getString("title_color")).toString()).intValue()); + } + else + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement(INSERT_CHAR_COLOR); + statement.setInt(1, getObjectId()); + statement.setString(2, Integer.toHexString(getAppearance().getNameColor()).toUpperCase()); + statement.setString(3, Integer.toHexString(getAppearance().getTitleColor()).toUpperCase()); + statement.execute(); + } + } + catch (Exception e) + { + _log.warning("could not restore colors: "+e); + } + finally + { + try{ con.close(); statement.close(); rset.close();} + + catch(SQLException e) {} + } + } + + /** + * Store colors + * @author =) + */ + private void storeColor() + { + + Connection con = null; + PreparedStatement statement = null; + try + { + con = L2DatabaseFactory.getInstance().getConnection(); + statement = con.prepareStatement(UPDATE_CHAR_COLOR); + statement.setString(1, Integer.toHexString(getAppearance().getNameColor()).toUpperCase()); + statement.setString(2, Integer.toHexString(getAppearance().getTitleColor()).toUpperCase()); + statement.setInt(3, getObjectId()); + statement.execute(); + } + catch (Exception e) + { + _log.warning("could not store colors: "+e); + e.printStackTrace(); + } + finally + { + try + { + con.close(); statement.close(); + } + catch(SQLException e) {} + } + }And MYSQL
7 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now