Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. package zensiert;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.Calendar;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.plugin.Plugin;
  12.  
  13. import com.mysql.jdbc.PreparedStatement;
  14.  
  15. import net.whitemine.lobbysystem.main.Main;
  16.  
  17. public class MySQL
  18. {
  19. private String HOST = "";
  20. private String DATABASE = "";
  21. private String USER = "";
  22. private String PASSWORD = "";
  23.  
  24. private Connection connection;
  25.  
  26. public MySQL(String host, String database, String user, String password)
  27. {
  28. this.HOST = host;
  29. this.DATABASE = database;
  30. this.USER = user;
  31. this.PASSWORD = password;
  32. connect();
  33. }
  34.  
  35. public void connect()
  36. {
  37. try
  38. {
  39. connection = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
  40. System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  41. }
  42. catch (SQLException e)
  43. {
  44. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
  45. }
  46. }
  47.  
  48. public void close()
  49. {
  50. try
  51. {
  52. if(connection != null)
  53. {
  54. connection.close();
  55. System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
  56. }
  57. }
  58. catch (SQLException e)
  59. {
  60. System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
  61. }
  62. }
  63.  
  64. public void update(String qry)
  65. {
  66. try
  67. {
  68. Statement st = connection.createStatement();
  69. st.executeUpdate(qry);
  70. st.close();
  71. }
  72. catch (SQLException e)
  73. {
  74. connect();
  75. System.err.println(e);
  76. }
  77. }
  78.  
  79. public ResultSet query(String qry)
  80. {
  81. ResultSet rs = null;
  82. try
  83. {
  84. Statement st = connection.createStatement();
  85. rs = st.executeQuery(qry);
  86. }
  87. catch (SQLException e)
  88. {
  89. connect();
  90. System.err.println(e);
  91. }
  92. return rs;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement