Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. public static String HOST = "localhost";
  2. public static String DATABASE = "Lobby2";
  3. public static String USER = "root";
  4. public static String PASSWORD = "localhost1P2";
  5. private static Connection con;
  6.  
  7. public Connector(String host, String database, String user, String password)
  8. {
  9. HOST = host;
  10. DATABASE = database;
  11. USER = user;
  12. PASSWORD = password;
  13.  
  14. connect();
  15. }
  16.  
  17. public void connect()
  18. {
  19. try
  20. {
  21. this.con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
  22. System.out.println(ChatColor.DARK_GREEN + "[BungeeSystem] Die Verbindung mit der MySQL Datenbank wurde hergestellt");
  23. }
  24. catch (SQLException e)
  25. {
  26. System.out.println(ChatColor.RED + "[BungeeSystem] Es konnte keine Verbindung zur MySQL Datenbank hergestellt werden es ist folgender Fehler aufgetreten: " + e.getMessage());
  27. }
  28. }
  29.  
  30. public void close()
  31. {
  32. try
  33. {
  34. if (this.con != null) {
  35. this.con.close();
  36. }
  37. }
  38. catch (SQLException localSQLException) {}
  39. }
  40.  
  41. public void update(String qry)
  42. {
  43. try
  44. {
  45. Statement st = this.con.createStatement();
  46. st.executeUpdate(qry);
  47. st.close();
  48. }
  49. catch (SQLException e)
  50. {
  51. connect();
  52. System.err.println(e);
  53. }
  54. }
  55.  
  56. public ResultSet query(String qry)
  57. {
  58. ResultSet rs = null;
  59. try
  60. {
  61. Statement st = this.con.createStatement();
  62. rs = st.executeQuery(qry);
  63. }
  64. catch (SQLException e)
  65. {
  66. connect();
  67. System.err.println(e);
  68. }
  69. return rs;
  70. }
  71.  
  72.  
  73. public static Connection getConnection()
  74. {
  75. return con;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement