CharNameTable.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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
  59. {
  60. con.close();
  61. }
  62. catch (Exception e)
  63. {
  64. }
  65. }
  66. return result;
  67. }
  68. public int accountCharNumber(String account)
  69. {
  70. java.sql.Connection con = null;
  71. int number = 0;
  72. try
  73. {
  74. con = L2DatabaseFactory.getInstance().getConnection();
  75. PreparedStatement statement = con.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE account_name=?");
  76. statement.setString(1, account);
  77. ResultSet rset = statement.executeQuery();
  78. while (rset.next())
  79. {
  80. number = rset.getInt(1);
  81. }
  82. rset.close();
  83. statement.close();
  84. }
  85. catch (SQLException e)
  86. {
  87. _log.warning("could not check existing char number:" + e.getMessage());
  88. }
  89. finally
  90. {
  91. try
  92. {
  93. con.close();
  94. }
  95. catch (Exception e)
  96. {
  97. }
  98. }
  99. return number;
  100. }
  101. }