CharNameTable.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.datatables;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.util.logging.Logger;
  20. import net.sf.l2j.L2DatabaseFactory;
  21. /**
  22. * This class ...
  23. *
  24. * @version $Revision: 1.3.2.2.2.1 $ $Date: 2005/03/27 15:29:18 $
  25. */
  26. public class CharNameTable
  27. {
  28. private static Logger _log = Logger.getLogger(CharNameTable.class.getName());
  29. private static CharNameTable _instance;
  30. public static CharNameTable getInstance()
  31. {
  32. if (_instance == null)
  33. {
  34. _instance = new CharNameTable();
  35. }
  36. return _instance;
  37. }
  38. public boolean doesCharNameExist(String name)
  39. {
  40. boolean result = true;
  41. java.sql.Connection con = null;
  42. try
  43. {
  44. con = L2DatabaseFactory.getInstance().getConnection();
  45. PreparedStatement statement = con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?");
  46. statement.setString(1, name);
  47. ResultSet rset = statement.executeQuery();
  48. result = rset.next();
  49. rset.close();
  50. statement.close();
  51. }
  52. catch (SQLException e)
  53. {
  54. _log.warning("could not check existing charname:"+e.getMessage());
  55. }
  56. finally
  57. {
  58. try { con.close(); } catch (Exception e) {}
  59. }
  60. return result;
  61. }
  62. public int accountCharNumber (String account)
  63. {
  64. java.sql.Connection con = null;
  65. int number = 0;
  66. try
  67. {
  68. con = L2DatabaseFactory.getInstance().getConnection();
  69. PreparedStatement statement = con.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE account_name=?");
  70. statement.setString(1, account);
  71. ResultSet rset = statement.executeQuery();
  72. while(rset.next())
  73. {
  74. number = rset.getInt(1);
  75. }
  76. rset.close();
  77. statement.close();
  78. }
  79. catch (SQLException e)
  80. {
  81. _log.warning("could not check existing char number:"+e.getMessage());
  82. }
  83. finally
  84. {
  85. try { con.close(); } catch (Exception e) {}
  86. }
  87. return number;
  88. }
  89. }